Test Url Exists - July 2012

If you download this tip please consider making a modest donation.

Recently I needed to test the existence of a Url. I searched the web and found some inspirational code which I converted from C# to VB.Net. I encapsulated the code in a class module which I call 'cExistsUrl'. The process is described in this July 2012 tip-of-the-month. I created an Asp.Net, VB.Net application to demonstrate the process. Click here to run the demo.

The Demo Application

The Asp.Net, VB.Net, VS/2008 project Test Url Exists is documented here.


The entered Url is tested and returns an 'exists' message.


The entered Url is tested and returns a does not exist message.
I found that a not exist condition is returned if the site is password protected.

The Class Module

Imports System.Net

Public Class cExistsUrl

    Public Function ExistsURL(ByVal sUrl As String) As Boolean   
        Dim
req As WebRequest = WebRequest.Create(sUrl)
        Dim res As WebResponse
        Try
            res = req.GetResponse()
            Return True
        Catch
        End
Try
    End
Function

End Class

Inspirational Code

I found some code on the web that inspired this tip. Click here to view that code. Scroll down and look for Solution 2.

Download the VB.Net Code

Download the source code by clicking on the zipped file name. Click here to run the demo application.

Download - Source Zipped File Size
VS/2008 VB.Net, ASP.Net Solution ExistsUrl.zip 60k

Previous Tip    Tip Index    Next Tip

Home

Updated 2012/09/06