Computing MD5 Checksum to identify unique files
Last Update: 08 January, 2010

MD5 Checksum is used to identify files throughout the servers and computers. MD5 Checksum is said to be unique for every different file in the computers as well as whole system of the world(although it should not give any grantee!).
Suppose 2 file, one named "The Matrix.avi" and other "The ONe.DAT" can be checked whether they contain same contents or not, through MD5 checksum. The renaming of file does not have any influence of checksum result.

 

My Code:

//Add these namespace
using System.IO;
using System.Security.Cryptography;

// The function that will return MD5 CheckSUM for a file
string ComputeMD5CheckSum(string fileName)
{
            FileStream file = new FileStream(fileName, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);
            file.Close();

            string str = "";
            for (int i = 0; i < retVal.Length; i++)
            {
                str += retVal[i].ToString();
            }
            return str;
}