Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing to a client from an ASP.NET application on the web server

Status
Not open for further replies.

smk7579

Programmer
Aug 10, 2005
11
US
I've written an ASP.NET (VS 2005) application that will print a receipt automatically when a command button is pressed. Here is an excerpt of the code that I am using to do this:


Dim printFont As New Font("COURIER NEW", 12)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage

pd.PrinterSettings.Copies = 2

' Specify the printer to use
pd.PrinterSettings.PrinterName = "\\awnse01\Generic"

If pd.PrinterSettings.IsValid Then
pd.Print()
Else
lbError.Text = "Printer is invalid."
End If


The client name is awnse01and server name is webserver1. The printer is installed on uhaditse02 and application resides on webserver1. However, when I go to print, it will NOT print.

The only way it will print is if I turn the client (awnse01) into a web server and run the application locally. I then change this line of code to the following:

pd.PrinterSettings.PrinterName = "Generic / Text Only"

While it works and I can go with this arrangement as a last resort, I'd rather not due to security reasons. And there is no sense in having more than one copy of this application on the network.

How would I allow a program running on the server to control a printer attached to the client?
I tried impersonation and running the program as my personal username. I also tried giving permissions to the local printer, but it still did not print. Can anyone help? This is urgent and any help would be GREATLY appreciated!
 
The only way you could do this would be to use an ActiveX component and then your users would have to use IE and accept that component.

As an alternative, you could use the javascript window.print function which will ask the user to select and confirm the printer.

Ideally, you would just show the user the receipt and tell them to print it for their records if they want.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
It does work....

But I have to run the software on the same machine as the printer is located, so I'll have to turn both clients into web servers. Luckily the software is only being used a couple of days and there are only 2 computers that need to run this. Thanks for your input.
 
It does work....
Yes, it works if you make both machines the server (which is where the code executes). If you want it to work in a situation where you will have one web server and multiple clients (i.e like a website's intended use), you will have to follow the advice I gave above.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top