Link to home
Start Free TrialLog in
Avatar of GRChandrashekar
GRChandrashekarFlag for India

asked on

Default Printer

I am using the following code to get list of printers and then to see whether it is default printer.

public static bool PaperSize()
        {
            foreach (string printerName in PrinterSettings.InstalledPrinters)
            {
                var printer = new PrinterSettings();
                printer.PrinterName = printerName;


                if (printer.IsDefaultPrinter)
                {
                    foreach (PaperSize size in printer.PaperSizes)
                    {
                        if (Enum.IsDefined(size.Kind.GetType(), size.Kind))
                        {
                            string PSize = size.Kind.ToString();
                            if (PSize == "A4")
                            {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }

Problem
If the default printer is network printer, it returns false ! How to solve this
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

That does more than see if it's the default printer.  It checks if it's the default and supports A4 paper size.  Maybe your network printer(s) don't accept A4.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,

public static string DefaultPrinterName()
{
string functionReturnValue = null;
System.Drawing.Printing.PrinterSettings oPS = new System.Drawing.Printing.PrinterSettings(…

try {
functionReturnValue = oPS.PrinterName;
}
catch (System.Exception ex) {
functionReturnValue = "";
}
finally {
oPS = null;
}
return functionReturnValue;
}