How to lock a file with C#?

后端 未结 3 756
庸人自扰
庸人自扰 2020-11-29 06:36

I\'m not sure what people usually mean by \"lock\" a file, but what I want is to do that thing to a file that will produce a \"The specified file is in use\" error message w

3条回答
  •  渐次进展
    2020-11-29 07:15

    As per http://msdn.microsoft.com/en-us/library/system.io.fileshare(v=vs.71).aspx

    FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.None);
    

提交回复
热议问题