錯誤: 「字符串」不包含關於「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'被拒絕。 而且該文件夾不是隻讀的。無論我在哪裏設置保存位置,它都會給我提供相同的錯誤。
哦,男人,我只是看着你的代碼之一,你的代碼,並希望我沒有,雖然我笑了起來! – 2012-07-07 22:38:15
@MattRoberts LOL是第一個嗎? – SimpleVar 2012-07-07 22:41:30
@MattRoberts擔心檢查的情況下,它是nsfw xD – user3564421 2016-01-21 15:30:07