C#获取文件版本和MD5值

        ///


        /// 获取文件版本
        ///

        /// 文件绝对路径
        ///
        private static string GetFileVerSion(string a_strFilePath)
        {
            try
            {
                FileVersionInfo ff = FileVersionInfo.GetVersionInfo(a_strFilePath);
                return ff.FileVersion;
            }
            catch (Exception)
            {
                return "";
            }
        }

///


        /// 获取文件MD5值
        ///

        /// 文件绝对路径
        /// MD5值
        public static string GetMD5HashFromFile(string fileName)
        {
            try
            {
                FileStream file = new FileStream(fileName, FileMode.Open);
                System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(file);
                file.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);
            }
        }

你可能感兴趣的:(底层库(工具,通用类),文件版本,Md5值)