[2005] Check remote file exists
I implemented some code I found elsewhere on this forum to check for the existence of a remote file.
VB Code:
Public Function IsFileAvailable(ByVal FileLink As String) As Boolean
Dim objUrl As New System.Uri(FileLink)
Dim objWebReq As System.Net.WebRequest
Dim objResp As System.Net.WebResponse
objWebReq = System.Net.WebRequest.Create(objUrl)
Try
objResp = objWebReq.GetResponse
objResp.Close()
objWebReq = Nothing
Return True
Catch ex As Exception
objWebReq = Nothing
Return False
End Try
End Function
But if I search for a remote file that I know does not exist, I get a 404 error response and the function bombs out, it does not jump to the Catch? Can anyone see what Im doing wrong?
Re: [2005] Check remote file exists
I just noticed that it does throw the exception if I build and run the app outside of the IDE. Is there an option I should be setting?
Re: [2005] Check remote file exists
Hi,
I did try your code with one more line inside the Try block (though it worked for me without that change).
VB Code:
Public Function IsFileAvailable(ByVal FileLink As String) As Boolean
Dim objUrl As New System.Uri(FileLink)
Dim objWebReq As System.Net.WebRequest
Dim objResp As System.Net.WebResponse
Try
objWebReq = System.Net.WebRequest.Create(objUrl)
objResp = objWebReq.GetResponse
objResp.Close()
objWebReq = Nothing
Return True
Catch ex As Exception
objWebReq = Nothing
Return False
End Try
End Function
Debugged via IDE and didn't find any problem. :)