To get the list of printer queue we call the method GetPrintQueues. This method has a number of signatures for populating different kind of printers.
PrintServer localPrintServer = new PrintServer();
If you do not pass any argument (i.e localPrintServer.GetPrintQueues()), it will just return the printer queue attached directly to your machine.
But as we need the network printers as well, so we will add some spice to this method.
If you do not pass any argument (i.e localPrintServer.GetPrintQueues()), it will just return the printer queue attached directly to your machine.
But as we need the network printers as well, so we will add some spice to this method.
PrintQueueCollection printQueues = localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
The no argument function and with just EnumeratedPrintQueueTypes.Local argument are equivalent to each other.
So, your complete function will look something like this.
List<PrintQueue> GetPrinters() { PrintServer localPrintServer = new PrintServer(); PrintQueueCollection printQueues = localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }); var printerList = (from printer in printQueues select printer).ToList(); return printerList; }
Note : you will need to add reference to System.Printing namespace