0

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\");

    }
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
Chris L
  • 103
  • 1
  • 12

1 Answers1

4

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");
}                                     ↑
dtb
  • 213,145
  • 36
  • 401
  • 431
  • The file name is not given in the RSS feed - which is actually the issue I am having (ie. RSS FEED: http://backend.deviantart.com/rss.xml?q=gallery%3Amr--jack%2F9678590&type=deviation). The RSS feed only contains the link I have with no filename. How can I get the filename? – Chris L May 09 '12 at 16:55
  • Maybe you can use the id that is in the url. It's up to you which name do you want/need for that file. – Ivo May 09 '12 at 16:56
  • It seems "the filename" you're referring to is the location to which your URL redirects. See: [Getting the location from a WebClient on a HTTP 302 Redirect?](http://stackoverflow.com/q/2603816/76217) – dtb May 09 '12 at 17:01