0

How can i figure out whether default printer is on or not using vb.net or C# (on .Net 2.0)

And what is the port number to which printer is attached.

I am using PrinterSettings Class, but there is no method in it to get those values.

Sudz
  • 4,268
  • 2
  • 17
  • 26

2 Answers2

1

You can get port number using this code.

private void cboPrinters_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  PrintQueue printer = cboPrinters.SelectedItem as PrintQueue;
  string portname = printer.QueuePort.Name;
}
Priscilla Jobin
  • 609
  • 7
  • 19
  • thanks but PrintQueue is not supported in .Net 2.0. Any other way? – Sudz May 09 '13 at 05:31
  • Check this link if it can help. http://www.codeproject.com/Articles/6069/How-to-Check-if-your-Printer-is-Connected-using-C – Priscilla Jobin May 09 '13 at 05:38
  • Hey try this link [link](http://www.codeproject.com/Articles/6069/How-to-Check-if-your-Printer-is-Connected-using-C) – Neeraj Dubey May 09 '13 at 05:41
  • @Priscy,@Neeraj Dubey: Guys the link you mention above uses System.Management which is not supported by .Net 2.0. Any other solution? – Sudz May 09 '13 at 06:05
0

Use Following:

string strDefaultPrinter;
using(var printServer = new LocalPrintServer())
{
  strDefaultPrinter= printServer.DefaultPrintQueue.FullName);
}

In this way you can set default printer in one string and can compare with detected printer.

Freelancer
  • 9,008
  • 7
  • 42
  • 81