[英]The filename, directory name, or volume label syntax is incorrect, File.Copy
I'm trying to copy a file from network shared folder to another folder in the same network. 我正在尝试将文件从网络共享文件夹复制到同一网络中的另一个文件夹。 It threws the exception .
它抛出了例外 。
Verified and the file exists . 已验证且文件存在 。
Source: \\servername\folder1\Old\ABC_1382.pdf
Destination: \\servername\folder1\New\
File.Copy(sourceFilePath, destiFilePath, true);
The file size is 400Kb. 文件大小为400Kb。
Both Source
and Destination
should be file names . Source
和Destination
都应该是文件名 。 If destiFilePath
is in fact a directory , let's add source file name ( ABC_1382.pdf
) 如果
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.