简体   繁体   中英

Save/Copy a file in a directory from another

using : asp .net mvc 4.0, c# , vs10

strFilePath holds a path of a existing file in a directory. I want to save/copy the file into my application's uploads directory.

how could i do this. I am trying something foolish, and searching the internet and feeling helpless.

string filePath = "foo.txt";
//var path = Path.Combine(Server.MapPath("~/Uploads"), filePath);
if (System.IO.File.Exists(filePath))
{
    System.IO.File.Copy(filePath, "~/Uploads");
}

~ symbol is not recognized by File.Copy

Convert virtual path to physical path first and then do the copy.

System.IO.File.Copy(filePath, Server.MapPath("~/Uploads"));

Also, You need permission to the folder where you are copying. You may need to Impersonate if the above does not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM