Results 1 to 3 of 3

Thread: [2005] Check remote file exists

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    [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:
    1. Public Function IsFileAvailable(ByVal FileLink As String) As Boolean
    2.         Dim objUrl As New System.Uri(FileLink)
    3.         Dim objWebReq As System.Net.WebRequest
    4.         Dim objResp As System.Net.WebResponse
    5.         objWebReq = System.Net.WebRequest.Create(objUrl)
    6.         Try
    7.             objResp = objWebReq.GetResponse
    8.             objResp.Close()
    9.             objWebReq = Nothing
    10.             Return True
    11.         Catch ex As Exception
    12.             objWebReq = Nothing
    13.             Return False
    14.         End Try
    15.     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?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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?

  3. #3
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    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:
    1. Public Function IsFileAvailable(ByVal FileLink As String) As Boolean
    2.         Dim objUrl As New System.Uri(FileLink)
    3.         Dim objWebReq As System.Net.WebRequest
    4.         Dim objResp As System.Net.WebResponse
    5.         Try
    6.             objWebReq = System.Net.WebRequest.Create(objUrl)
    7.             objResp = objWebReq.GetResponse
    8.             objResp.Close()
    9.             objWebReq = Nothing
    10.             Return True
    11.         Catch ex As Exception
    12.             objWebReq = Nothing
    13.             Return False
    14.         End Try
    15.     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
  •  



Click Here to Expand Forum to Full Width