這是微軟的代碼示例,用不同的文件位置,這是行不通的:新的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