How to lock a file with C#?
You need to pass in a FileShare
enumeration value of None
to open on the FileStream
constructor overloads:
fs = new FileStream(@"C:\Users\Juan Luis\Desktop\corte.txt", FileMode.Open,
FileAccess.ReadWrite, FileShare.None);
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);