Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

please tell me how to write code to backup a file/folder from source to destination at a specific date every week...

and if the system in shut down then also it should run as a backup process.
Posted

Well This could be very easy .

You can use the following code

C#
string sourceFolder = @"c:\update\files";
string outputFolder = @"D:\weeklybackup\"+Convert.ToString(DateTime.Today);
// Code to create outputfolder.
new Microsoft.VisualBasic.Devices.Computer().
    FileSystem.CopyDirectory( sourceFolder, outputFolder );


I always prefer This code over Directory.Move Method because FileSystem.CopyDirectory takes care of all folder,subfiloder and files.

Now after building / compling your code. Dont write a service. Simply add your exe to schedule tasks in your server. I hope u know what are schedule task and how they work.
 
Share this answer
 
v2
Comments
Menon Santosh 16-Nov-12 1:01am    
useful code but need some changes in code, any way my +5 for its simplicity
 
Share this answer
 
v3
Comments
[no name] 26-Oct-12 8:39am    
please tell me how to do..??
Ambesha 26-Oct-12 8:48am    
update my solution please refer. accept the solution and rate the article if relevent
[no name] 26-Oct-12 8:52am    
Why you need a service ? Service runs all the time and will use memory unneccessaryly.
Ambesha 26-Oct-12 8:54am    
user want continues and automated process :)
PRASHANT KUMAR LAL 26-Oct-12 8:56am    
agree with Ambesha, if you have any idea then tell us.. my 5 to Ambesha

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



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