|
-
Jan 14th, 2007, 04:40 PM
#1
[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?
-
Jan 14th, 2007, 05:17 PM
#2
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?
-
Feb 9th, 2007, 07:16 PM
#3
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|