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   
req As WebRequest = WebRequest.Create(sUrl)
        Dim res As WebResponse
            res = req.GetResponse()
            Return True

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


Updated 2012/09/06