.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?

The public is stable

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.

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

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -