これらの次のコードを使用して、C# Windows アプリケーションで特定の URL からファイルをダウンロードします。
private void button1_Click(object sender, EventArgs e)
{
string url = @"DOWNLOADLINK";
WebClient web = new WebClient();
web.DownloadFileCompleted += new AsyncCompletedEventHandler(web_DownloadFileCompleted);
web.DownloadFile(new Uri(url), @"F:\a");
}
void web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("The file has been downloaded");
}
しかし、この行にはエラーがあります:web.DownloadFile(new Uri(url), @"F:\a");
それは言います:
WebClient リクエスト中に例外が発生しました。