gpt4 book ai didi

c# - 文件名、目录名或卷标语法不正确 - 映射共享网络驱动器 (ASP.NET MVC3 C#)

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:08 25 4
gpt4 key购买 nike

您好,我正在尝试将文件复制到共享网络,但我继续收到错误消息文件名、目录名或卷标语法不正确。有人可以请捕获我做错了什么。我的应用程序也在使用 ASP.NET MVC3 运行,谢谢!

复制代码

File.Copy(@path, @Properties.Settings.Default.SharedMappedOutput);

路径是一个参数: C:\log\12345.pdf
Properties.Settings.Default.SharedMappedOutput 路径: \\vfler_xx\evl_xx\VT\

我想要完成的事情:我想将文件从 Path (文件名)复制到 SharedMappedOutput (目录)


额外信息

  • window 服务器 2008 R2
  • IIS 7.5
  • ASP.NET MVC3 C#

编辑
我在@Steve 的帮助下更改了我的代码,但现在它说我无权访问我未指定的路径。

String dest_path = Properties.Settings.Default.SharedMappedOutput;
File.Copy(@path, Path.Combine(dest_path, Path.GetFileName(path)));

错误
访问路径“c:\windows\system32\insetsrv\12345.pdf”被拒绝我没有指定这条路径,我不确定它为什么要访问这条路径。

链接到新问题 https://stackoverflow.com/questions/16179585/iis-acccess-to-the-path-c-windows-system32-inetsrv-12345-pdf-is-denied


谢谢。如果问题中有任何问题或误解,请告诉我。再次提前致谢。

最佳答案

File.Copy 不会将一个目录复制到另一个目录,而只是一个文件名。

您的 c:\log 似乎只是一个目录的名称,如 documentation at MSDN 所述这行不通

要复制源路径中的所有文件,您可以这样写

string destPath = Properties.Settings.Default.SharedMappedOutput;
foreach (string aFile in Directory.GetFiles(path, "*.*"))
File.Copy(aFile, Path.Combine(destPath, Path.GetFileName(aFile)));

编辑看到关于真实源名称的评论,答案仍然部分有效,因为目标也应该是文件名而不是目录。所以答案就变成了

string sourceFile = @"C:\log\12345.pdf";
string destPath = Properties.Settings.Default.SharedMappedOutput;
File.Copy(sourceFile, Path.Combine(destPath, Path.GetFileName(sourceFile)));

关于c# - 文件名、目录名或卷标语法不正确 - 映射共享网络驱动器 (ASP.NET MVC3 C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16178913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com