簡體   English   中英

文件名,目錄名或卷標語法不正確,File.Copy

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

SourceDestination都應該是文件名 如果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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM