How can I determine if printer is connected?
Typically this application prints to the default printer but in some cases that printer may not be available. If so I don’t want the job sent to it’s queue but rather printed to another available printer.
I understand the PrinterSettings.InstalledPrinters property. Does PrintDocument.PrinterSettings.IsValid return false if a printer is not available?
Does WPF provide this kind of functionality?
My problem is different than Printing problem in C# windows app – Always prints to default printer
First, IsValid checks the value of the PrinterName property to see if it is a valid value, not if the printer is connected.
Second, in WPF it is very easy to do this;
Check the docs for more detail:
In winforms, its a little harder but you can use WMI. Reference System.Management.dll and add the following using statements:
To get all default printers:
NOTE The following code is likely to be OS dependant to some extent. Check the MSDN docs..
The WMI documentation for the printer object describes some useful structures we can look at; PrinterStatus and WorkOffline. We can use these to write an utility class to check the availability of the printer, also check its WorkOffline state…
Now you can combine this with standard WinForms System.Drawing.Printing code:
Hope this helps