Friday 28 December 2012

Check internet connection

System.Net.WebClient   //Name space

Solutions 1:  
Public Void InternetConnCheck()
{     
     try
     { 
        WebClient Client=new WebClient ();
       Using (var stream = client.OpenRead("http://www.google.com")
       {       
           Messagebox.show("Connection is Open"); 
       }
     catch
     {
          Messagebox.show("Connection Not available");  
     }   

}

Solutions 2: 

Public Void InternetConnCheck()
{     
     try 
     {       
       System.Net.IPHostEntry i = System.Net.Dns.GetHostEntry("www.google.com");
               Messagebox.show("Connection available");        
     }
     catch
     { 
        Messagebox.show("Connection Not available"); 
     }  

}

Solutions 3: 
bool InternetConnection = new Ping().Send
                          ("www.google.co.in").Status == IPStatus.Success;

No comments:

Post a Comment