1

I am making a data backup program. I need to copy files from one folder to another, while some files are still being used by a running process. It's OK when the running process shares file access. But I will get exception if files are not shared. (FileShare.None)

I am wondering if there is any way to read a non-shared file in C#.

Thanks,

ChrisJ
  • 5,161
  • 25
  • 20
user648912
  • 63
  • 1
  • 3
  • 2
    What if that process is writing the data to locked file and you want to back it up? Wont it be corrupt since the write has never completed? I'd say if the file is non-shared there is a reason for that... – Cipi Mar 11 '11 at 21:24
  • That's true. But the files I want to backup are mainly for reading (by some running process). So I wouldn't care too much about data corruption at this step. – user648912 Mar 11 '11 at 21:53
  • Is it permissible to make a volume shadow copy and backup off of that? – Gabe Mar 13 '11 at 00:08

2 Answers2

0

C# under the hood uses the file access operations your operating system provides, including its file sharing behavior. So I'm afraid C# cannot go beyond this.

C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
0

There is a technique if you are using Vista or later. You can use the Volume Shadow Copy feature. However, getting to work in C# will be tedious, and all that I can provide for help are references. However, if you wanted to administrate a solution instead of developing one, you could use Windows Backup to copy the files on a schedule.

Links:

Ritch Melton
  • 11,498
  • 4
  • 41
  • 54