http://www.codeproject.com/Questions/602895/SelfplusMD5plusCheckplusWhenplusFormplusLoad
把自身文件路径作为参数传递不就可以了吗?
private string GetFileMd5Code(string filePath) { StringBuilder builder = new StringBuilder(); using(var md5=new MD5CryptoServiceProvider()) { File.Copy(filePath,filePath+"e");//复制一份,防止占用 using(FileStream fs=new FileStream(filePath+"e",FileMode.Open)) { byte[] bt=md5.ComputeHash(fs); for (int i = 0; i < bt.Length; i++) { builder.Append(bt[i].ToString("x2")); } } File.Delete(filePath+"e");//删除复制的文件,这里没处理异常等.... } return builder.ToString(); }
当前exe的fileStream吗?
试试这个:
var fileStream = Assembly.GetExecutingAssembly().GetFile("ConsoleApplication19.exe");