On Thu, 31 May 2007 07:30:12 -0700, Kimmo Laine <re******@newsg roup.only>
wrote:
Is there a way to check if file is already open/used by another process?
I know that i can do something like this to check it ["try/catch"
snipped]
but I would rather use some method then try to open the file in write
mode.
Why do you want this information?
Note that if you do not yourself open and lock the file, then checking
whether the file is open at any given moment in time is pointless. A
split second after you make the check, the state could change.
If you need to open the file yourself, then just try to open it. If you
don't need to open the file yourself, then there is not usually really any
use in knowing whether the file is already open or used by another process.
(One exception would be if you are trying to write a tool similar to the
Sysinternals FileMon utility, but the kind of things that tool does
requires much lower-level coding than .NET provides).
Pete