![](/img/trans.png)
[英]File.Copy Throwing throw “The filename, directory name, or volume label syntax is incorrect” error
[英]The filename, directory name, or volume label syntax is incorrect, File.Copy
我正在嘗試將文件從網絡共享文件夾復制到同一網絡中的另一個文件夾。 它拋出了例外 。
已驗證且文件存在 。
Source: \\servername\folder1\Old\ABC_1382.pdf
Destination: \\servername\folder1\New\
File.Copy(sourceFilePath, destiFilePath, true);
文件大小為400Kb。
Source
和Destination
都應該是文件名 。 如果destiFilePath
實際上是一個目錄 ,那么讓我們添加源文件名( ABC_1382.pdf
)
string sourceFilePath = @"\\servername\folder1\Old\ABC_1382.pdf";
string destiFilePath = @"\\servername\folder1\New\";
// Uncomment, if you are not sure that directory exists
// and you want to create it with all subdirs
// Directory.CreateDirectory(destiFilePath);
File.Copy(sourceFilePath,
Directory.Exists(destiFilePath)
? Path.Combine(destiFilePath, Path.GetFileName(sourceFilePath))
: destiFilePath,
true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.