Check the Status of a Printer


/ Published in: C#
Save to your folder(s)

Amazingly fast. Doesn't throw exceptions if the printer doesn't exist.


Copy this code and paste it in your HTML
  1. public bool IsValid
  2. {
  3. get
  4. {
  5. bool retVal = false;
  6. try
  7. {
  8. PrintDocument pd = new PrintDocument();
  9. pd.PrinterSettings.PrinterName = printerName;
  10. retVal = pd.PrinterSettings.IsValid;
  11. }
  12. catch(System.Exception ex)
  13. {
  14. string errorMsg = "";
  15. errorMsg = "Printer Error:" + printerName + ex.ToString();
  16. Trace.WriteLine(errorMsg);
  17. retVal = false;
  18. }
  19. return retVal;
  20. }
  21. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.