Method 1
Step 1: Add a quote
using ;
Step 2: Code
public static List<string> GetPrintList() { List<string> lt = new List<string>(); LocalPrintServer printServer = new LocalPrintServer(); PrintQueueCollection printQueuesOnLocalServer = (new[] { }); foreach (PrintQueue printer in printQueuesOnLocalServer) (); return lt; }
Method 2
Need to be introduced
accomplish
1. Get the printer list
2. Get the default printer
3. Set the default printer
On the code
public class PrinterExample { /// <summary> /// Set the default printer /// </summary> /// <param name="Name"></param> /// <returns></returns> [DllImport("")] public static extern bool SetDefaultPrinter(String Name); //Calling win api to set the printer with the specified name as the default printer /// <summary> /// Get the default printer /// </summary> /// <returns></returns> public static string GetDefaultPrinter() { PrintDocument print = new PrintDocument(); string defaultName = ;//Default printer name return defaultName; } /// <summary> /// Get all local printers /// </summary> /// <returns></returns> public static List<String> GetLocalPrinters() { List<String> printer_names = new List<String>(); foreach (String item in ) { printer_names.Add(item); } return printer_names; } /// <summary> /// Get all local printers /// </summary> /// <returns></returns> public static List<String> GetLocalPrinters2() { List<String> printer_names = new List<String>(); ManagementObjectCollection queryCollection; string _classname = "SELECT * FROM Win32_Printer"; Dictionary<string, ManagementObject> dict = new Dictionary<string, ManagementObject>(); ManagementObjectSearcher query = new ManagementObjectSearcher(_classname); queryCollection = (); foreach (ManagementObject mo in queryCollection) { string oldName = mo["Name"].ToString(); printer_names.Add(oldName); } return printer_names; } }
This is all about this article about getting the printer list in C#. I hope it will be helpful to everyone's learning and I hope everyone will support me more.