C# calculate MD5 for opened file?

浪尽此生 提交于 2019-12-03 07:07:57

Try opening the file as read-only:

FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);

or:

FileStream file = File.OpenRead(fileName);

That will work depending on the sharing mode of the other file handles. If the file is only locked because it is a running EXE, I think this will be enough.

If you update your FileStream constructor call to this;

FileStream file = File.Open(fileName,
                            FileMode.Open,
                            FileAccess.Read,
                            FileShare.ReadWrite);

That should allow you to open a file which is being used by another process.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!