【发布时间】:2012-07-07 21:55:54
【问题描述】:
错误: “string”不包含“SelectedPath”的定义,并且找不到接受“string”类型的第一个参数的扩展方法“SelectedPath”
代码:
private static string fbd = String.Empty;
public void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select a Folder to save the images.";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
textBox1.Text = fbd.SelectedPath;
}
public void button3_Click(object sender, EventArgs e)
{
List<string> address = new List<string>();
Random r = new Random();
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600000_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600001_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600002_460s.jpg");
address.Add("http://d24w6bsrhbeh9d.cloudfront.net/photo/4600003_460s.jpg");
//MessageBox.Show(address[r.Next(0, 4)]);
if (comboBox1.Text == "10")
{
string filename = fbd.SelectedPath;
MessageBox.Show(fbd);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(address[r.Next(0, 4)]));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect) &&
response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
{
using (Stream inputStream = response.GetResponseStream())
using (Stream outputStream = File.OpenWrite(filename))
{
byte[] buffer = new byte[4096];
int bytesRead;
do
{
bytesRead = inputStream.Read(buffer, 0, buffer.Length);
outputStream.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
using (WebClient client = new WebClient())
{
client.DownloadFile(address[r.Next(0, 25)], filename);
}
}
}
}
}
说明: 对于 button3_Click 我试图让它调用您设置的保存位置以保存图像。我在网上找遍了,我没有找到解决这个问题的方法:/
当我手动输入保存位置时,我也遇到了错误。 拒绝访问路径“H:\images”。 没有文件夹不是只读的。无论我在哪里设置保存位置,它都会给我同样的错误。
【问题讨论】:
-
哦,伙计,我只是从您的代码中查看了您的一张图片,并希望我没有,尽管我笑了!
-
@MattRoberts LOL 是第一个吗?
-
@MattRoberts 担心检查是否是 nsfw xD
标签: c#