2

Is there a good way to check if a file locked other than attempting to open in as a text reader and looking for an exception?

I guess I could do this:

try
{
    stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (IOException)
{
    ....
}

Is there a better way?

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Bill
  • 132
  • 1
  • 1
  • 10
  • 1
    What's the point? If you check it and it's not locked there's nothing stopping it being locked before you try to do something with the file. You can't avoid the exception so you should code for it. – Enigmativity Nov 24 '15 at 04:36

0 Answers0