Hi guys, 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
-
Here's a link that tells you what APIs to search for MSDN. And some code too.
-
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)); }
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.