Pergunta

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

    }
Foi útil?

Solução

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");
}                                     ↑
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top