Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I determine if an URL is valid

Status
Not open for further replies.

voyageur

MIS
Feb 19, 2002
29
0
0
CA
Is there an easy way to programmatically determine if a website URL actually points to a live page so that I can filter out non-existent pages so end users don't have to find out for themselves when they click on the hyperlink?
 
try to connect to it.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I'm sure there are cleaner ways, but this works.
:) -Andrew
Code:
    Sub CheckExist()
        Dim uri As String
        Dim wc As New System.Net.WebClient
        uri = "[URL unfurl="true"]http://www.doesnotexist.com/doesnotexist.asp"[/URL]
        Try
            wc.DownloadData(uri) ' Try to download page
        Catch ex As Exception
            If Err.Number = 5 Then
                ' Page does not exist
                MsgBox("Page does not exist.")
            Else
                MsgBox(Err.Number & vbCrLf & Err.Description)
                Exit Sub
            End If
        End Try
        MsgBox("Page Exists")
    End Sub

alien.gif

[TAG]
... If you find my posts helpful, rate me up! ...
anongod@hotmail.com
'Drawing on my fine command of language, I said nothing.'
 
Thanks for the code Andrew. It works great in normal VB.NET. I'll give it a try where I really need it...in a SQL Report Server RDL report.
 
in a SQL Report Server RDL report.
Uhhh, I'm not sure that's a good idea.

If the URI doesn't exist you'll be waiting for the DNS timeout (30 seconds or more), and I don't know what SQL Server will do with a report that is unresponsive for that length of time.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top