MD TAHMID HOSSAIN
MD TAHMID HOSSAIN

Reputation: 1720

How to copy or read Spool file in C# (Winforms)

i need to copy or read spool file. but when i try to read/copy it. i get following error.

System.UnauthorizedAccessException: Access to the path 'C:\Windows\System32\spool\PRINTERS\00007.SPL' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost) at System.IO.File.Copy(String sourceFileName, String destFileName) at WDISYS.wfPrintServerLogin.Addedtest(Object sender, PrintJobEventArgs e) in F:\Projects\Asp.Net\AT\A2Test\WDISYS\WDISYS\wfPrintServerLogin.cs:line 255

my code is like below :

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);
}

Upvotes: 0

Views: 1765

Answers (1)

Lance Hall
Lance Hall

Reputation: 202

Try giving the spool folder full rights. Right-click the folder, click "Properties", and then click the "Security" tab. Click "Edit" after "Advanced" and select Replace permission entries on all child objects with entries shown here that apply to child objects.

Upvotes: 1

Related Questions