I want to get the default printer name with the network path. Because i am using the network printer as a default printer. So i need this in VB.NET or C#.Net. Kind help needed. Thanks in advance
Sivakumar.P
Try enumerating System.Drawing.Printing.PrinterSettings.InstalledPrinters
.
using System.Drawing.Printing;
string GetDefaultPrinter()
{
PrinterSettings settings = new PrinterSettings();
foreach (string printer in PrinterSettings.InstalledPrinters)
{
settings.PrinterName = printer;
if (settings.IsDefaultPrinter)
return printer;
}
return string.Empty;
}
This does not work too well. I had better experience on more machines with
DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);
StringBuilder dp = new StringBuilder(256);
int size = dp.Capacity;
if (GetDefaultPrinter(dp, ref size)) {
Console.WriteLine(String.Format("Printer: {0}, name length {1}", dp.ToString().Trim(), size));
} else {
int rc = GetLastError();
Console.WriteLine(String.Format("Failed. Size: {0}, error: {1:X}", size, rc));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With