Check if internet connection available in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

To check internet connection add the following function code:
Public Function IsConnectionAvailable() As Boolean
        Dim objUrl As New System.Uri("")
        Dim objWebReq As System.Net.WebRequest
        objWebReq = System.Net.WebRequest.Create(objUrl)
        Dim objresp As System.Net.WebResponse

            objresp = objWebReq.GetResponse
            objresp = Nothing
            Return True

        Catch ex As Exception
            objresp = Nothing
            objWebReq = Nothing
            Return False
        End Try
End Function
Then add the following code where you like to check the connection:

If IsConnectionAvailable() = TrueThen
Do Action Here
Do Action Here

End If

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.