Shadow open a file

I'm trying to backup a file to a web-service which I'm trying to upload segments, I've managed to get it working however I've now got a problem where the files are in use so I want to be able to create a shadow copy of the file and then open the file as a stream read and the read segments of the files.

What I have is now a problem as I have no idea how to create a shadow copy of a file and open a read stream to it. Im sure in .net 4 there is a method to shadow copy a file, but cannot find any documentation to it.

Any ideas?
tonelm54Asked:
Who is Participating?
 
Jacques Bourgeois (James Burger)PresidentCommented:
@kaufmed

Shadow copy is also a feature of Windows that enables you to copy a file even while it is in use. It is a low level feature of Windows that is used for instance by backup software.


@tonelm54

Im sure in .net 4 there is a method to shadow copy a file, but cannot find any documentation to it.

I would have said the same thing, but there are still a few thins in Windows that do not seem to be covered by .NET.

I am in .NET 4.5.5, and still nothing in the documentation about shadow copy. So I think you fell on one of these holes where you still have to use the system API. If you're up to it, the documentation starts in Volume Shadow Copy API Reference.

If it is only one file, I would suggest to simply wait for the file to be available and make a regular copy. A user would not like to wait to get the file, but a web service might not mind too much.

If you need to process multiples files in one batch, then you could do what we do here. Use a commercial backup program to perform the backup, and copy the file generated by that backup program to your service. You will gain the advantage that commercial programs already bundles all the tools you need to search through archives or restore files, something that you would have to build yourself for an in-house system.
0
 
käµfm³d 👽Commented:
The only time I've ever heard of "shado copy" pertains to .NET assemblies. Why do you think you need shado copy here?
0
 
käµfm³d 👽Commented:
@James

Ah. So it overrides file locking then? Because I know that if a program doesn't open a file with an exclusive lock, then you can still read it even if it's in use.

On a side note, there must be an EE goblin loose, stealing all of the Ws. I can't otherwise explain how I misspelled "shadow" twice    XD
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
I do mostly database work nowadays, so I haven't worked with files for a long while. But won't opening a file for writing automatically prevents reading by default?

As for the gremlins, I haven't been young for a long while either, so I might be out of touch about there current behavior, but in my times, they were usually in greater number around this time of the year. Simply improve the security in your brain by wearing a hat all the time, and you should be OK.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.