I want to call a specific printer to print in my WPF application. I have three printer Suppose Printer1 for Bar bill Print Printer2 for Kitchen bill Print Printer3 for Guest bill Print printers name already saved in database, while printing I get a printer name from DB and want to print from specific printer, not defaul printer Here is my code
var v = new PrinterDAL().GetPrinterSettings();
try
{
System.Threading.Thread thread = new System.Threading.Thread(new
System.Threading.ThreadStart(
delegate()
{
gridPrint.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(
delegate()
{
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = new PrintQueue(
new PrintServer(@"\\" + v.BarPrinter), "");
printDialog.PrintVisual(gridPrint, "");
this.Close();
}
));
}
));
thread.Start();
}
catch (Exception ex)
{
Xceed.Wpf.Toolkit.MessageBox.Show(ex.Message, "", MessageBoxButton.OK,
MessageBoxImage.Error);
}
I get an exception from this code
"An exception occurred while creating the PrintServer object. Win32 error: The printer name is invalid."
PrintServer must be instance using a computer or printer server device in UNC format (\\resource
) not a printer name:
For example, if the name of your computer, in your domain, is KashifPC and you have configured a printer, called "Printer1", you can use:
//example code. no error handling.
PrintServer localPS = New PrintServer(@"\\KashifPC")
PrinterQueue printer1 = localPS.GetPrintQueue("Printer1") //v.BarPrinter???
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = printer1
//rest of code
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