How to use LocalPrintServer to print on a specific printer?

Following this question: How do I get a list or number of jobs from a print queue?

I still stick with how to target a specific printer, of which I currently only know the name using the LocalPrintServer class. The application must print several machines at once, and all printers must be controlled separately. Can someone provide me with a code snippet that shows how I can instantiate a LocalPrintServer object using only the printer name?

Thanks in advance!

Edit: Added code snippet for solution:

private int GetNumberOfPrintJobs() { LocalPrintServer server = new LocalPrintServer(); PrintQueueCollection queueCollection = server.GetPrintQueues(); PrintQueue printQueue = null; foreach (PrintQueue pq in queueCollection) { if (pq.FullName == PrinterName) //PrinterName is a classmember printQueue = pq; } int numberOfJobs = 0; if (printQueue != null) numberOfJobs = printQueue.NumberOfJobs; return numberOfJobs; } 

It was not so difficult after all!

+3
c # queue printing
source share
2 answers

Try LocalPrintServer.GetPrintQueue with the printer name.

+4
source share

Important Note. GetPrintQueues does not return all printers installed from the user's point of view - only those that belong to the "local" local server.

More strange, but LocalPrintServer.DefaultPrintQueue not necessarily contained inside GetPrintQueues() , even if it comes from a LocalPrintServer object.

If you use System.Drawing.Printing.PrinterSettings.InstalledPrinters , which is string[] , you will get a list of all printers installed from the user's point of view.

Some of them may be on remote computers if you have installed a remote printer (on the print server). If it is an IP-accessible network printer, it will still be a local printer:

 "Send To OneNote 2010" "Microsoft XPS Document Writer" "HP LaserJet P2050 Series PCL6" "HP LaserJet 1020" "Fax" "\\\\ike\\LUCY" "\\\\shipping\\HP LaserJet 1020" 

To get a printout on a remote server, you need to do:

 new PrintServer("\\ike").GetPrintQueue("LUCY") 

Yes, you will need to disassemble it yourself.

+9
source share

All Articles