I'm trying to send a report direct to the default printer and this is already running ok with this code:
doc.Load(Server.MapPath("~\\reports\\CrystalReport\\DocumentCRV.rpt"));
doc.SetDataSource(dsReport);
doc.PrintToPrinter(1, true, 0, 0);
The problem is that it only works when i'm running the webapplication on my dev machine (so, i'm assuming th开发者_JAVA百科at it's getting the default printer for the server, not the user's printer)
There is no way to directly print to the users printer from the web server, unless possibly you are on the same internal network / directory. That would be a management nightmare.
Your best bet would be to pop open the viewer and then the print dialog.
I did use a active x control that could enumerate the end users printers and then automatically print it. However, it was IE only and poorly maintained.
Does the user have a default printer set up? Also, this article might help:
Choosing a printer when printing from Crystal Reports in C#
Controling user printers is not something that can be done from server-side code, as this would create potential security holes. The browser can be forced to print in JavaScript. Perhaps you could have the report be downloaded to the user? Then they can print from within a PDF viewer or something?
精彩评论