1

I'm trying to download files using the Net.WebClient call to DownloadFile

Using client As New Net.WebClient()   
  Try
    client.DownloadFile(PDFURL, FullPDFFilePath)

I then catch the exception and check the message for 403, 404, or 500 errors (the most common type for the system we are calling into.

 Catch ex as exception
   If exceptionMessage.Contains("(403)") Then 'Forbidden
     LogInformation("403 returned on download for " + CRPOrderNum, "DownloadLabels")

   ElseIf exceptionMessage.Contains("(404)") Then 'Not Found
     LogInformation("404 returned on download for " + CRPOrderNum, "DownloadLabels")

   else
     'blah blah
   end if
 finally
 end try

Is there a polite way I can ask for the file instead of calling DownloadFile, and handling the exception ?

Thanks in advance.

cometbill
  • 1,619
  • 7
  • 19
  • 41

1 Answers1

2

The "polite" way would be to send a HEAD request. Unfortunately WebClient doesn't support this natively so you'd either have to roll your own or use HttpWebRequest instead.

Community
  • 1
  • 1
Chris Haas
  • 53,986
  • 12
  • 141
  • 274