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