Results 1 to 2 of 2

Thread: [02/03] check web url

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    [02/03] check web url

    Hi,

    How to check whether a web url or image exists? (when we access it returns 404 not found error) ..

    thanks in advance
    Kanna

  2. #2
    New Member
    Join Date
    Sep 2008
    Posts
    4

    Re: [02/03] check web url

    This is an example of what I use in VB2008

    It checks the url in my.settings.enteredURL
    If it is a bad URL then it navigates the web browser on my form to http:\\www.google.com otherwise it navigates to the URL that it checked.

    Code:
        Sub updateURL()
    
            Dim URL As String
            Dim httpCheck As String = UCase(My.Settings.enteredURL)
    
            'Make sure URL starts with http
            If httpCheck.StartsWith("HTTP:\\") Or httpCheck.StartsWith("HTTP://") Then
                URL = My.Settings.enteredURL
            Else
                URL = ("http://" & My.Settings.enteredURL)
            End If
    
            Try
                Dim myWebClient As System.Net.WebClient = New System.Net.WebClient()
    
                Dim myStream As System.IO.Stream = myWebClient.OpenRead(URL)
    
                Dim myStreamReader As System.IO.StreamReader = New System.IO.StreamReader(myStream)
    
                Dim s As String = myStreamReader.ReadToEnd
    
                myStreamReader = Nothing
    
                myStream = Nothing
    
                myWebClient = Nothing
    
            Catch
    
                URL = "http:\\www.google.com"
    
            End Try
    
            webbrower1.Navigate(New Uri(URL))
    
        End Sub
    Hope This Helps!
    Last edited by jeremyslaton; Sep 17th, 2008 at 11:50 AM.

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