当我尝试将文件复制到新目的地时,我收到错误;
发生了'System.IO.DirectoryNotFoundException'类型的异常 在mscorlib.dll中但未在用户代码中处理
其他信息:无法找到路径的一部分 '〜/内容/ fileHistory / Resume.pdf'。
然而文件就在那里。
这是我的代码,找到了正确的fileName;
Random randNums = new Random();
string fileName = documentUps.Attachment ;
string newFileName = fileName + randNums;
string sourcePath = "~/Content/fileHistory/";
string targetPath = "~/Content/reviseFiles/";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, newFileName);
System.IO.File.Copy(sourceFile, destFile, true);
答案 0 :(得分:0)
请将此代码更改为:
Random randNums = new Random();
string fileName = documentUps.Attachment;
string newFileName = fileName + randNums;
string sourcePath = "~/Content/fileHistory/";
string targetPath = "~/Content/reviseFiles/";
// Use Path class to manipulate file and directory paths.
string sourceFile = Server.MapPath(System.IO.Path.Combine(sourcePath, fileName));
string destFile = Server.MapPath(System.IO.Path.Combine(targetPath, newFileName));
System.IO.File.Copy(sourceFile, destFile, true);