这是微软的代码示例,用不同的文件位置,这是行不通的:新的C# - 无法获得File.Copy工作
string fileName = "test1.txt";
string sourcePath = @"C:\";
string targetPath = @"C:\Test\";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
它不能找到源文件。如果我把一个破发点,这是我得到:
args {string[0]} string[]
fileName "test1.txt" string
sourcePath "C:\\" string
targetPath "C:\\Test\\" string
sourceFile "C:\\test1.txt" string
destFile "C:\\Test\\test1.txt" string
所以它看起来是加倍反斜杠即使使用原义字符串。 (毫无疑问,我在C中有一个test1.txt文件:)任何想法?谢谢!
什么是异常消息和堆栈跟踪? – SLaks 2012-04-10 14:13:38
反斜杠加倍仅用于显示。你收到什么错误信息。 – 2012-04-10 14:13:46
您能否发布例外文本?双反斜杠很好。 – Matten 2012-04-10 14:14:21