/// <summary>
/// 获取文件MD5值
/// </summary>
/// <param name="file">文件绝对路径</param>
/// <returns>MD5值</returns>
public static string GetMD5HashFromFile(string file)
{
try
{
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(fileStream);
fileStream.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
catch (Exception ex)
{
throw new Exception("GetMD5HashFromFile() fail,error:" + ex.Message);
}
}