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

c#, file-locking

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.

Problem

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 - How does one figure out what process locked a file using c#? - Command line tool - Across a Network - Locking a USB device - Unit test fails with locked file - deleting locked file

Original source

Related problems