【问题标题】:How to copy or read Spool file in C# (Winforms)如何在 C# (Winforms) 中复制或读取假脱机文件
【发布时间】:2017-01-07 13:09:34
【问题描述】:

我需要复制或读取假脱机文件。但是当我尝试阅读/复制它时。我收到以下错误。

System.UnauthorizedAccessException:访问路径 'C:\Windows\System32\spool\PRINTERS\00007.SPL' 被拒绝。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.File.InternalCopy(字符串源文件名,字符串 destFileName,布尔覆盖,布尔检查主机)在 System.IO.File.Copy(String sourceFileName, String destFileName) 在 WDISYS.wfPrintServerLogin.Addedtest(对象发送者,PrintJobEventArgs e) 在 F:\Projects\Asp.Net\AT\A2Test\WDISYS\WDISYS\wfPrintServerLogin.cs:line 255

我的代码如下:

try
{
    string dest = @"C:\Windows\sfwitch\spls";

    if (!System.IO.Directory.Exists(@"C:\Windows\sfwitch\spls"))
    {
        System.IO.Directory.CreateDirectory(@"C:\Windows\sfwitch\spls");
    }

    string spl_file = (e.PrintJob.JobId).ToString().PadLeft(5, '0');
    string printSpoolPath = @"C:\Windows\System32\spool\PRINTERS";
    printSpoolPath = System.IO.Path.Combine(printSpoolPath, spl_file) + ".SPL";

    System.IO.File.Copy(printSpoolPath, System.IO.Path.Combine(dest, spl_file) + ".SPL");
}
catch (Exception ex80)
{

    LogHelper.WriteErrorLog("Spool file create problem", ex80);
}

【问题讨论】:

  • 你试过以管理员身份运行 Visual Studio 吗?
  • 它发生在客户端电脑上。它适用于我的开发电脑。
  • 那么用户无权访问该位置。您的客户端需要尝试以管理员身份运行应用程序。
  • 客户端以管理员身份运行程序。这仍然在发生。为什么我在这里问。

标签: c# winforms


【解决方案1】:

尝试授予假脱机文件夹完整权限。右键单击该文件夹,单击“属性”,然后单击“安全”选项卡。单击“高级”后的“编辑”,然后选择将所有子对象上的权限条目替换为此处显示的适用于子对象的条目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2012-07-30
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多