GRChandrashekar
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.InstalledP rinters)
{
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
public static bool PaperSize()
{
foreach (string printerName in PrinterSettings.InstalledP
{
var printer = new PrinterSettings();
printer.PrinterName = printerName;
if (printer.IsDefaultPrinter)
{
foreach (PaperSize size in printer.PaperSizes)
{
if (Enum.IsDefined(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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello,
public static string DefaultPrinterName()
{
string functionReturnValue = null;
System.Drawing.Printing.Pr interSetti ngs oPS = new System.Drawing.Printing.Pr interSetti ngs(…
try {
functionReturnValue = oPS.PrinterName;
}
catch (System.Exception ex) {
functionReturnValue = "";
}
finally {
oPS = null;
}
return functionReturnValue;
}
public static string DefaultPrinterName()
{
string functionReturnValue = null;
System.Drawing.Printing.Pr
try {
functionReturnValue = oPS.PrinterName;
}
catch (System.Exception ex) {
functionReturnValue = "";
}
finally {
oPS = null;
}
return functionReturnValue;
}