Wednesday, June 10, 2009

How to check internet connection in C#

A simple example, for check internet connection is avilable or not
CODE:
1 :  Using System.Net ;
2 :  try{
3 :  HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create("abc.com");
4 :  HttpWebResponse webRes= (HttpWebResponse)webReq.GetResponse();
5 :  if (HttpStatusCode.OK == webRes.StatusCode)
6 :  {
7 :  webRes.Close();
8 :  // write code here...........
9 :  }
10 :  }
11 :  catch (Exception ex)
12 :  {
13 :  MessageBox.Show("Unable to connect");
14 :  }

No comments:

Post a Comment