Check Is Internet Connection Available?


Public
Function IsConnectionAvailable(ByVal URL As String) As Boolean
' Returns True if connection is available
' Replace www.yoursite.com with a site that
' is guaranteed to be online - perhaps your
' corporate site, or microsoft.com
Dim objUrl As System.Uri
Dim objWebReq As System.Net.WebRequest
Try
objUrl =
New System.Uri(URL)
' Setup WebRequest
objWebReq = System.Net.WebRequest.Create(objUrl)
Dim objResp As System.Net.WebResponse
' Attempt to get response and return True
objResp = objWebReq.GetResponse
objResp.Close()
objWebReq =
Nothing
Return True
Catch ex As Exception
' Error, exit and return False
'objResp.Close()
objWebReq =
Nothing
Return False
End Try
End Function