I'm trying to backup files on a server, but some of them are in use and cannot be opened. Instead, I'd like to open their shadow copy if the current copy is in use. How can I do this?
For reference, I'm using C# .net 3.5.
This question is quite old already, so my answer might not be of much use to you, but SO being a Q&A site maybe it still helps someone else.
I can't / don't want to put down the entire implementation, but the procedure is goes something like this:
You create a Volume Shadow Copy via the Volume Shadow Service Provider for the drive where your file to be read is located(this is well documented on MSDN, also there is a sample client that creates these shadow copies and will most likely be sufficient for you)
Either make a persistent one, or use the "callback" mechanism (calls your app)
Open the desired file via UNC paths and CreateFile (the UNC looks something like this: \\?\GlobalRoot\Devices\HarddiskVolumeShadowCopyXZY\yourpath\yourfile.yourextension)
Do whatever you want with the file
more info here: http://technet.microsoft.com/en-us/library/cc785914%28WS.10%29.aspx and here: http://msdn.microsoft.com/en-us/library/bb968832%28VS.85%29.aspx