Posted March 7, 201410 yr I have the following which sends a print file to a specific printer. It works perfectly in Windows 7, but not in Windows 8. The print job shows in the print queue until the print job jobstream is closed. Then the print job literally vanishes from the print queue. Here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Printing; namespace PrinterLib { public static class PrintToSpooler { public static string SendFileToPrinter(string szPrinterName, string szFileName, string docName) { try { // Create the printer server and print queue objects //PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue(); //PrintQueue mypq = new PrintServer().GetPrintQueue(szPrinterName); //using (var printq = defaultPrintQueue) using (var printq = new PrintServer().GetPrintQueue(szPrinterName)) { using (PrintSystemJobInfo job = printq.AddJob(docName)) { using (var memoryStream = new MemoryStream()) { FileStream fs = new FileStream(szFileName, FileMode.Open, FileAccess.Read, FileShare.None); fs.CopyTo(memoryStream); fs.Close(); Byte[] myByteBuffer = memoryStream.ToArray(); // Write a Byte buffer to the JobStream and close the stream job.JobStream.Write(myByteBuffer, 0, myByteBuffer.Length); job.JobStream.Flush(); } } printq.Commit(); } return null; } catch (Exception ex) { return ex.Message; } } } } Continue reading...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.