I have a text file and I want to check if it's open already. the problem is that it is posible to open the file multiple times and there is no exception.
I tried:
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
No exception.
I also tried
using (Stream stream = new FileStream("MyFilename.txt", FileMode.Open))
no exception.
And even
System.Diagnostics.Process.GetProcessesByName("MyFilename.txt").Length < 1
but even if the file is open it returns 0
.
MyFilename.txt
is just a name, in the real code it's the real file path.
What can I write insted?
Thanks! Grace