[英]Save/Copy a file in a directory from another
using : asp .net mvc 4.0, c# , vs10 使用:asp .net mvc 4.0,c#,vs10
strFilePath holds a path of a existing file in a directory. strFilePath保存目录中现有文件的路径。 I want to save/copy the file into my application's uploads directory.
我想将文件 保存/复制到我的应用程序的uploads目录中。
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 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.
如果以上操作不起作用,您可能需要进行模拟 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.