How to Load system D drive and download folders or Files

Posted by Nadh123 under C# on 9/18/2012 | Points: 10 | Views : 1628 | Status : [Member] | Replies : 4
How to Load system D drive and download folders or Files

Mahendra
91-9908699686



Responses

Posted by: T.Saravanan on: 9/19/2012 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try the below code... I hope you are coping the files from Source to Destination using Winforms. If you want to use webforms, not possible to get all the files from folders/ subfloders using loop. Because for the security purpose browser can't access our local machine drive. If you need to load the files, using multiple file upload controls for copying the files from local machine to server machine.

Add the namespace --> using System.IO

public void CopyFiles(string SourceDir, string DestDir)
{
if (!Directory.Exists(DestDir))
{
Directory.CreateDirectory(DestDir);
}

// Get files from Source & copy to Destination
string[] files = Directory.GetFiles(SourceDir);
foreach (string file in files)
{
string Filename = Path.GetFileName(file);

string dest = Path.Combine(DestDir, Filename);
File.Copy(file, dest);
}

// Get files from Subfolders
string[] folders = Directory.GetDirectories(SourceDir);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(DestDir, name);
CopyFiles(folder, dest);
}
}


Thanks,
T.Saravanan

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

Posted by: Ravi12345 on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
yes saravana i lik this code it works properly?
i am not tested this code i hope it is right?/


ravi.....

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

Posted by: Seng2hs on: 11/8/2012 [Member] Starter | Points: 25

Up
0
Down
Need to understand your question..
Do you want to download files & folder from Server???
Do you want this to be developed in ASP.NET or Windows forms??


Thanks




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

Posted by: Ravi12345 on: 11/9/2012 [Member] Starter | Points: 25

Up
0
Down
hi saravana from both can give me answer please?


ravi.....

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

Login to post response