.net - C# calculate MD5 for opened file? -
How can I calculate the MD5 hash for a file that is open or used in a process?
it is going files string GetMd5HashFromFile (String filename) {FileStream file = new FileStream (filename, FileMode.Open); MD5 md5 = new MD5CryptoServiceProvider (); Byte [] retVal = md5.ComputeHash (file); File.Close (); Stringbilder sb = new stringbiller (); For (Int i = 0; I Cheers. The public is stable
Try opening the file to read - only:
FileStream file = new filestream (FileName, FileMod. Open, FileAccess. Read);
Or:
file stream file = file. OpenRide (filename);
This will work on the sharing mode of other file handles if the file is locked only because it is a running EXE, I think it would be sufficient
Comments
Post a Comment