简体   繁体   English

将文件保存/复制到另一个目录中

[英]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.

相关问题 将文件从一个目录复制到另一个目录 - Copy file from one directory to another 命令将文件复制到另一个目录? - Command to copy a file to another directory? 使用C#中的cmd将文件从一个目录复制到另一个目录 - Copy file from one directory to another using cmd in C# FileNotFoundException尝试将文件从一个目录复制到另一个目录时 - FileNotFoundException While trying to copy the file from one directory to another 将一个项目的 output 目录中的一个文件复制到另一个项目的 output 目录 - Copy one file from a project's output directory to another project's output directory 将文件从列表框复制到另一个目录 - Copy files from listbox to another directory 将文件从服务器复制到另一个 - copy file from server to another C#:如何仅将文件中的差异从一个目录复制到另一个目录 - C#: How to copy only the differences in a file from one directory to another 如何在没有System.UnauthorizedAccessException的情况下将文件从应用程序捆绑包复制到另一个目录? - How to copy a file from the app bundle to another directory without System.UnauthorizedAccessException? 为什么将文件从一个目录复制到另一个目录时,文件名会被切断? - Why does my filename cut-off when I copy a file from one directory to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM