Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Got Net?
Message
General information
Forum:
ASP.NET
Category:
Forms
Title:
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01001686
Message ID:
01001764
Views:
17
This message has been marked as the solution to the initial question of the thread.
>How can I test for an active Internet connection in a WinForm application?
    Public Shared Function IsWebAccessible() As Boolean
        'Source: http://www.dotnet247.com/247reference/msgs/23/118934.aspx
        'Source : http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=68
        Dim hwrRequest As System.Net.HttpWebRequest
        Dim hwrResponse As System.Net.HttpWebResponse

        Dim strUrl As String = "http://www.microsoft.com/"
        Dim bConnected As Boolean = False

        Try
            hwrRequest = CType(System.Net.WebRequest.Create(strUrl), System.Net.HttpWebRequest)
            hwrResponse = CType(hwrRequest.GetResponse(), System.Net.HttpWebResponse)

            If hwrResponse.StatusCode = System.Net.HttpStatusCode.OK Then
                bConnected = True
            End If

        Catch we As System.Net.WebException
            bConnected = False
        Catch ex As Exception
            bConnected = False
        Finally
            hwrRequest = Nothing
            hwrResponse = Nothing
        End Try

        Return bConnected
    End Function
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Reply
Map
View

Click here to load this message in the networking platform