how to copy a folder to another folder on button clk in asp.net

Posted by Shanky11 under ASP.NET on 10/6/2012 | Points: 10 | Views : 945 | Status : [Member] | Replies : 2
i hav a buttton and two different folder in d drive and e drive i want to copy all contents inside folder named test to anothe folder named backup
how can i do that dont send links




Responses

Posted by: Jayakumars on: 10/6/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code

protected void bt1_Click(object sender, EventArgs e)
{
string sourcePath = @"C:\Jesus";
string targetPath = @"D:\Jesus";

if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string s in files)
{
string fileName = System.IO.Path.GetFileName(s);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.Directory.CreateDirectory(@"D:\Jesus");
System.IO.File.Copy(s, destFile, true);
}
Response.Write("Sucessfully Created");
}

}



Mark as Answer if its helpful to you

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kotra.Ramakrishna on: 10/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try this code.

     string sourcePath=@"D\MainFolder";

string destinationPath = @"E\BackupFolder";
if(Directory.Exists(sourcePath) && Directory.Exists(destinationPath))
File.Copy(sourcePath, destinationPath);


Thanks & Regards
Ramakrishna.k

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response