atrljoe
atrljoe

Reputation: 8151

WebClient.DownloadFile download file that is dynamically created

I have a file that is dynamically created (ie I request it via a handler http://example.com/images/1849?encoding=UTF-8&b=100) It creates the image based on what attributes you pass in. I am trying to figure out how to use WebClient.DownloadFile to grab this file but cannot get it to work has anyone done this before? The error does not tell me anything "System.Net.WebException: An exception occurred during a WebClient request."

  WebClient Client = new WebClient();
  Client.DownloadFile("http://example.com/images22?encoding=UTF-8&b=100", @"c:\myfile.jpeg");

Upvotes: 0

Views: 3598

Answers (2)

Immersive
Immersive

Reputation: 1704

Can't comment, need rep...

Have you tried wrapping the DownloadFile in a Try / Catch block and then displaying the error details? Specifically, if it's a HTTP error, or some other system error?

Upvotes: 2

Guvante
Guvante

Reputation: 19223

The second string parameter is a local file to download to, such as C:\image.bmp.

You could instead use DownloadData if you want a byte array to work with instead.

Upvotes: 1

Related Questions