Unable to save image from URL in C# - using Webclient and DownloadFile();
-
07-06-2021 - |
سؤال
I am unable to download images from an RSS Feed, where the URL doesn't contain a filename.
Example -
Image URL I would like to download (it works if you click on it in a browser, but in code it doesn't work):
http://www.deviantart.com/download/286471805/
Using the code below I get a "An exception occurred during a WebClient request." error. I have no idea why this isn't working.
Any ideas on how I can save these files?
private void Start_Button_Click(object sender, EventArgs e)
{
WebClient MyDownloader = new WebClient();
MyDownloader.DownloadFile(@"http://www.deviantart.com/download/286471805/", @"c:\test\");
}
المحلول
You have to specify a file name as the second argument, not the download directory:
using (var client = new WebClient())
{
client.DownloadFile("http://www.deviantart.com/download/174633066/",
@"c:\test\file.png");
} ↑
لا تنتمي إلى StackOverflow