Question

I have a file that is dynamically created (ie I request it via a handler http://mysite.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://mysite.com/images22?encoding=UTF-8&b=100", @"c:\myfile.jpeg");
Was it helpful?

Solution

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?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top