0

I am downloading a file with the WebClient class, but sometimes the file returns as HTML (I can't do anything about this) What I would like to do is check whether the content is HTML or not using the WebClient class, my code is as follows:

client.DownloadFile(downloadURL, "downloadedfile.zip");
James Teare
  • 372
  • 1
  • 12
  • 23
  • You should probably set AutoRedirect to false in which case you will be able to know if file doesn;t exist or other error cases.. I guess webclient doesnt have this property but other classes should have it. – Sandeep Singh Rawat Jun 09 '12 at 20:45

1 Answers1

1

One solution might be to use UrlMon:

Another might WebResponse.ContentType:

I believe the latter is simply part of the WebClient response headers:

Try whichever looks most promising, and let us know what you find!

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190