Reputation: 5
I am developing asp.net web service using win7 IIs server.under IIs root dir there are two sub dir how can i copy file from one sub folder to another this my try:
string fileName="file.txt";
string sourcePath = @"localhost\C:\inetpub\wwwroot\source";
string targetPath = @"localhost\C:\inetpub\wwwroot\dest";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
thanks in advance
Upvotes: 0
Views: 2502
Reputation: 26
You should use physical paths. That is :
string fileName="file.txt";
string sourcePath = @"C:\inetpub\wwwroot\source";
string targetPath = @"C:\inetpub\wwwroot\dest";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
If you need to involve the website root (in this case, folders on the site root folder), it should be like this:
string fileName="file.txt";
string sourcePath = Server.MapPath("/source");
string targetPath = Server.MapPath("/dest");
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
Best
Upvotes: 1