to copy folders from local machine to folder in server
to copy folders from local machto copy the complete files and folders , from local machine , i.e, folder/directory path which is selected by user has to be completely[all files within the path is be selected] is to be pasted/copied into folder which is in webserver where 开发者_开发知识库the web application has been hosted. ine to folder in server
Well, I've had quite a difficult time understanding your English. As I understood, your task is to make an exact copy of one folder including all nested folders and files, in some location? If yes, then I would highly recommend using the console command xcopy for that, as it is perfomance-wise optimized and gives the benefit of copying the file-structure with all the related security permissions etc.
Try this:
string[] SourceFilez = System.IO.Directory.GetFiles("path", "*.*", System.IO.SearchOption.AllDirectories);
string[] targetFilez = new string[SourceFilez.Length];
SourceFilez.CopyTo( targetFilez, 0 );
for(int i = 0; i < targetFilez.Length; ++i)
{
targetFilez[i] = targetFilez[i].Replace("oldfolder", "newfolder");
string strThisDirectory = System.IO.Path.GetDirectoryName(targetFilez[i]);
if (!System.IO.Directory.Exists(strThisDirectory))
{
System.IO.Directory.CreateDirectory(strThisDirectory);
}
System.IO.File.Copy(SourceFilez[i], targetFilez[i]);
}
You might want to include the for loop content in a try-catch-finally block.
To account for empty directories, you might want to repeat the same code-block without file.copy, replacing SourceFilez with:
string[] SourceDirectories = System.IO.Directory.GetDirectories("path", "*.*", System.IO.SearchOption.AllDirectories);
If you have IIS7 and the user does not have the necessary permissions to write to the target folder, you need to use identity impersonate and switch the app-pool to classic mode.
Edit:
Or do you mean a way to upload all files in a folder on a web-application's user's computer to the server at once ? In that case you need JQuery uploadify:
http://www.uploadify.com/
精彩评论