How can I programmatically tell if a caught IOException is because the file is being used by another

Posted by Paul K on Stack Overflow See other posts from Stack Overflow or by Paul K
Published on 2010-04-02T19:58:48Z Indexed on 2010/04/02 20:03 UTC
Read the original article Hit count: 311

Filed under:
|
|
|

When I open a file, I want to know if it is being used by another process so I can perform special handling; any other IOException I will bubble up. An IOException's Message property contains "The process cannot access the file 'foo' because it is being used by another process.", but this is unsuitable for programmatic detection. What is the safest, most robust way to detect a file being used by another process?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about file