1

Possible Duplicate:
how do i check if a printer is installed and ready using C#?

i use PDFCreator to make pdf files from my program in C# while i have an Exception for general error, i want to know how i can check if the printer itself exist in the system.

something like the file exist check.

is there such an option?

Community
  • 1
  • 1
Iakovl
  • 1,013
  • 2
  • 13
  • 20
  • 2
    This is answered in this post: [http://stackoverflow.com/questions/1622903/how-do-i-check-if-a-printer-is-installed-and-ready-using-c][1] [1]: http://stackoverflow.com/questions/1622903/how-do-i-check-if-a-printer-is-installed-and-ready-using-c – Shaunak Mar 11 '12 at 08:48

2 Answers2

7

You can know by using the PrintDialog

System.Windows.Forms.PrintDialog dlg=new PrintDialog();
if(dlg.PrinterSettings.IsValid)
      MessageBox.Show("Printer Exist: "+ dlg.PrinterSettings.PrinterName);
else
      MessageBox.Show("Printer Does Not Exist");
MDMalik
  • 3,951
  • 2
  • 25
  • 39
  • Note: If the printer is on a server and you specify the UNC name to the printer on the server it's checking if the printer is valid on the server. It does not check if there is a queue on your computer pointing to that printer. – Jeff Nov 08 '19 at 19:11
  • Alternately you can loop through the printers looking for the one you are interested in: foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { ....} – Jeff Nov 08 '19 at 20:50
3

you can use the PrinterSettings class (MSDN docs here) but, perhaps, even better would be to let the user locate the printer he wants to use by leveraging the PrintDialog class (MSDN docs here)

Muad'Dib
  • 28,542
  • 5
  • 55
  • 68