得到文件的MD5值

/// <summary>
        /// 得到文件的MD5值
        /// </summary>
        /// <param name="Path">文件路径</param>
        /// <returns></returns>
        public static string GetFileMD5Code(string Path)
        {
            try
            {
                if (System.IO.File.Exists(Path))
                {
                    System.IO.FileStream Get_File = new System.IO.FileStream(Path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                    System.Security.Cryptography.MD5CryptoServiceProvider Get_MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                    byte[] Hash_byte = Get_MD5.ComputeHash(Get_File);
                    string Result = System.BitConverter.ToString(Hash_byte);
                    Result = Result.Replace("-", "");
                    return Result;
                }
                else
                {
                    return "文件路径错误!";
                }
             
            }
            catch (Exception e)
            {
               return e.Message;
            }
        }
View Code

 

posted @ 2015-02-15 14:08  whatever_pds  阅读(673)  评论(0)    收藏  举报