Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
4.50/5 (3 votes)
See more:
Hi there , I am new to programming only been doing it for a few months. I am attempting to make a very easy backup program that backs up all of Appdata folder in c:\users\dave\appdata. ( window 7 ) I have tried several ways including listed below :-

1) My.Computer.FileSystem.CopyDirectory("c:\users\dave\APPDATA", "d:\server\users\dave\appdata", overwrite:=True)

When trying this i get " access to path c:\users\dave\appdata\roaming\application data\ is denied.
Also this way does copy the directory name but folders are empty.

2) My.Computer.FileSystem.CopyDirectory("c:\users\dave\appdata\", "d:\server\users\dave", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)

3) Also tried getfiles & getdirectories but does the same as number 1.

When doing it this way it does allow me access and does copy but keep getting dialogs saying " this action can not be complete because the file is open " etc. I wanted this to run at night on my computers at work and didnt want user interaction.

I have tried turning UAC off and selecting and de-selecting one click but still cant get it to work. I am also aware of the issues with "My documents " not copying because its actually called " Documents ".

I could use DOS Xcopy but it defeats the object i realy wanted a nice GUI and didnt want to use DOS at all.

Sorry for the long explanation !!!!! Hopefully someone can help as i have tried everything within my power and am out of steam !!!

Thanks in advance, Dave.
Posted
Comments
Dave Lowe - Falcon 13-Jan-11 15:44pm    
Thanks for quick posts !!! Will look into shadow copy is it compatible with visual studio 2010 ? The import vss doesnt seem to work ?? as said i am a noob !!! Thanks Valery

Thanks john i realy wanted to write my own software.
#realJSOP 13-Jan-11 15:50pm    
I like to write my own stuff too, but if something breaks, I really would rather have someone else to blame. :)
Dave Lowe - Falcon 13-Jan-11 17:13pm    
lol ye suppose you corect John !! Just having a look at using shell xcopy will do the job now worries until i get time to write something that works !

Thanks Dave will hve a look at doing it your way , getfiles be best way ?? then vet each file , suppose need to write something that is like xcopy.

Hi,

An easy solution to copy files that are in use is to use Shadow Copy.

Have a look at this article it will explain you how to do it.

Volume Shadow Copies from .NET[^]

Good luck ;)

Valery.
 
Share this answer
 
My advice is to buy Acronis TrueImage Home, and do let that perform your nightly backups. It's relatively inexpensive at $50, and you can just set it and forget it. It'll perform any kind of backup you might require, and save your hundreds of hours of time trying to figure out how to make your own code do it.

I have it, and it's just freakin great.
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 13-Jan-11 15:58pm    
Agreed. 5+
I'm using it too and have never looked back since.
The reason why your code doesn't work is because there are system files that are held open so long as the machine is running and/or there is a user logged in.

The solution is to not use those My.xxx functions but to enumerate the folders and files in each folder, creating the folder structure and copying them individually, and handling all errors in the process. You can attempt to copy those locked files, but it'll fail. You just handle the error appropriately by skipping that file and keep going for the next file/folder.

You'll, of course, end up not copying everything, but those are usually files/folders that you don't want to restore if you need to restore the users stuff.
 
Share this answer
 
http://alphavss.codeplex.com

Using the Windows Volume Shadow Copy Service (VSS) on the .NET platform in C# (or VB) is somewhat problematic to say the least.

To further complicate things there are actually multiple versions of VSS depending on what version of Microsoft Windows you are running and for which platform it is targeted. Most notably Windows XP and Windows Server 2003 requires compiling and linking your application against the Shadow Copy Service SDK 7.2, with separate header files and libraries depending on the version of Windows you are targeting. From Windows Vista and onwards things are simpler though with all the functionality available in the standard Windows SDK.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900