Search code examples
c#file-locking

How do I find out which process is locking a file using .NET?


I've seen several of answers about using Handle or Process Monitor, but I would like to be able to find out in my own code (C#) which process is locking a file.

I have a nasty feeling that I'm going to have to spelunk around in the win32 API, but if anyone has already done this and can put me on the right track, I'd really appreciate the help.

Update

Links to similar questions


Solution

  • One of the good things about handle.exe is that you can run it as a subprocess and parse the output.

    We do this in our deployment script - works like a charm.