Thursday, January 16, 2014

How to check internet connection using C#


I just created a small program for detecting internet connection on computer, that will be use for uploading of local database to central server

Here is the sample code

using System.Net;

public static bool CheckForInternetConnection()
        {
            try
            {

                using (var client = new WebClient())
                using (var stream = client.OpenRead("http://google.com.ph"))
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }