错误:“字符串”不包含“SelectedPath”的定义,并且找不到接受“字符串”类型的第一个参数的扩展方法“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”。没有文件夹不是只读的。无论我在哪里设置保存位置,它都会给我同样的错误。