【问题标题】:Access To The Path Is Denied From F#F# 拒绝访问路径
【发布时间】:2018-11-23 11:40:45
【问题描述】:

我已阅读此post。我正在尝试在 Windows 服务器上将文件从一个位置移动到另一个位置。运行 F# 程序的用户拥有执行 .Net File.Move 语句的完全权限,我使用使用文件资源管理器登录服务器的同一用户手动测试了此移动。

我想弄清楚我做错了什么。

这里是相关代码,copyOnly就是false

let rc =
    try
       if copyOnly then
          File.Copy((currentPath + fnam), (destPath + new_file_dest)) |> ignore
          logH.WriteLine(generateTimeStamp () + ": " + currentPath + fnam + " copied to " + (new_file_dest + fnam))
       else
          File.Move((currentPath + fnam), (destPath + new_file_dest)) |> ignore
          logH.WriteLine(generateTimeStamp () + ": " + currentPath + fnam + " moved to " + destPath + new_file_dest)
                true 
    with ex -> 
       logH.WriteLine(generateTimeStamp () + ": " + "An error occrred trying to move or copy " + currentPath + fnam + " to " + (destPath + new_file_dest))
       printfn "%A" ex
       false
rc

currentPath = \\\\Munis2\\musys_read\\musys\\import_prod\\
fnam = import_arlckbox.007
destPath = \\\\Munis2\\Munis_IC_DataExchange\\archive\\
new_file_dest = import_arlckbox_6132018_15645.007

我很困惑为什么这是一个问题。查看另一篇文章 (post),我确实确保我正在测试的两个用户在所有目录中都具有完全权限,并且我正在将一个文件移动到另一个目录中的另一个文件名。这是参考文章中的一项决议。

我有第二个与错误相关的问题。如果我尝试使用 URL 路径语法调试此问题,如上所述,哪个用户尝试在服务器上执行此任务?

该用户是否与在 Visual Studio 中调试的工作站上的用户相同,或者移动或复制请求是否由默认 Internet 用户处理?

我问这个问题,因为在修复损坏的路径问题后,我仍然无法访问路径被拒绝使用 URL 进行错误调试,但当应用程序直接在服务器上运行时却没有。

【问题讨论】:

  • 您能否具体解释一下currentPathdestPath 的值是如何在程序中获取或声明的?我想知道它是否与某种方式的双反斜杠无关(或在musys_read\musys 中没有)...
  • @ThomasCorbière 我发现了问题。这是一条糟糕的道路。

标签: .net file f#


【解决方案1】:

我不知道 F#,但在 Windows 应用程序或 Windows Server 中,您需要使用 Application ExecutablePath 并删除 bin\Debug,如图所示

 string startupPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) + "\\Templates");

 startupPath = startupPath.Replace("bin\\Debug\\", string.Empty);

 var newfileName2 = Guid.NewGuid() + ".xlsx";

 string destinationPath = Path.Combine(startupPath, newfileName2);

 File.Copy(sourcefile, destinationPath, true);

这是 C# 代码。发布此代码以了解您的问题

【讨论】:

  • 此程序正在使用 URL 路径在 Visual Studio 2012 之外执行,这是出于调试目的。生产应用程序使用驱动器号和路径,并得到相同的错误。所以,我对你的回答感到困惑。
【解决方案2】:

首先,存在路径问题。部分路径(没有文件名)被复制到带有文件名的完整路径中。一旦应用程序的 Access 数据库(程序使用的路径的来源)重新设置为使用标准 Windows 驱动器路径 -- G:\dir1\dir2\file1.007 并且修复了无效路径,程序就会恢复正常。

如果File.Move(或复制)能提供更可靠的错误,那就太好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-11
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多