Generate MD5 checksum from file

Sometimes we have the necessity to verify that the file we downloded wasn’t corrupted. A way to do this it’s to generate a MD5 checksum and verify the file integrity.

The purpose of this check is to establish that the file has not been modified by someone.

        public string GetMD5HashFromFile(string fileName)
            FileStream file = new FileStream(fileName, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)

            string checksum = sb.ToString();

            return checksum;

Verify internet connection in C#

The method below vefiry the internet connection in the easiest way as possible.

public bool InternetConnectionAvailable()
     bool connectionAvailable = false;
     if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
          connectionAvailable = true;
     return connectionAvailable;