Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Got Net?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01001686
Message ID:
01001764
Vues:
16
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform