printing from asp net to a network printer

printing from asp net to a network printer  using -'c#,.net,,printing,system.printing'

I need to send documents to a network printer (\myserver\myprinter).  I'm using the System.Printing classes to print, and it works fine when it's from a Windows Service, but from an ASP.NET app, it's only able to print to local printers, not network printers.  The error I'm getting is "Printer Name is not valid" This is what I'm using to get the printer name:

public string PrinterName
   using (LocalPrintServer server = new LocalPrintServer())
   return server.GetPrintQueue(@"\\myserver\myprinter");

What are my options here?  Is this a permissions problem?  

asked Sep 21, 2015 by okesh.badhiye
0 votes

2 Answers

0 votes

There are issues with credentials that you could solve by impersonation or elevating rights of the user the web app is running under.

However, we did it by adding the network printer as a printer on the server (add printer dialogue on server) and having the job sent to that printer.

We used the Printing.PrintDocument like so (Code in VB)....

Public Class SpecialReportPrintJob
  Inherits Printing.PrintDocument

Protected Overrides Sub OnBeginPrint(ByVal ev as Printing.PrintEventArgs)

  Me.PrinterSettings.PrinterName = "PrinterNameUsedOnServer"

  'setup rest of stuff....
End Sub  
End Class
'And we then call it like so
Dim printSpecialReport as new SpecialReportPrintJob()
answered Sep 21, 2015 by ajit.chavhan
0 votes

By default, an ASP.NET application runs on a special account with limited rights. Just enough to serve webpages, nothing more. So you'll have to configure the ASPNET user.

By contrast Windows services usually run under local System account (with high privileges)

answered Sep 21, 2015 by rajeshujade