Click here to Skip to main content
14,932,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
always print to server's printer

What I have tried:

Dim doc As New ReportDocument
doc.Load("..\CrystalReport4.rpt")
doc.PrintToPrinter(1, True, 0, 0)
Posted
Updated 20-Aug-18 10:26am

The code is running at the server and accesses therefore the printer of the server.

For security reasons such code running on the server has no or very restricted access to the client's hardware. But there are solutions to print Crytal Reports on the client:
Crystal Reports Client Side Printing without the Viewer[^]
Print Crystal Report Directly in ASP.NET C# - Stack Overflow[^]
   
Comments
Member 13954973 20-Aug-18 22:49pm
   
Thanks a lot.

I knew how to use the Crystal Report prints to the printer, but just need to
(1) select conditions , press the print button then show the report.
(2) press crystal report print button .
(3) choice the printer then printing.
I wrote:
Dim oRpt As New ReportDocument
oRpt.Load(Server.MapPath("T13RLABEL.rpt"))
Dim mytablelogoninfo As New TableLogOnInfo
Dim mytable As Table
For Each mytable In oRpt.Database.Tables
mytablelogoninfo = mytable.LogOnInfo
With mytablelogoninfo.ConnectionInfo
.ServerName = ConfigurationSettings.AppSettings("ServerString")
.DatabaseName = ConfigurationSettings.AppSettings("DatabaseString")
.UserID = ConfigurationSettings.AppSettings("UidString")
.Password = ConfigurationSettings.AppSettings("PwdString")
End With
mytable.ApplyLogOnInfo(mytablelogoninfo)
Next
oRpt.RecordSelectionFormula = "{T13LABEL.USER_ID} = """ & sys_user & """"
oRpt.Refresh()

CreportV.ReportSource = oRpt
Jochen Arndt 21-Aug-18 2:48am
   
Did you understand what I and the other's wrote?
Code can only access printer's of the local system where it is running. Because your code is running on the server, it can't access the client's printer.

There are tricks to allow clients to print reports as shown in the links from my solution. But then choosing the printer and selecting printer options must be performed on the client which requires to be initiated by the user.
Member 13954973 21-Aug-18 3:21am
   
I understood.
Thanks.
It prints to the server's printer because your code is running on the server, it has no access to the client's hardware. You can't print to the user's printer from your web code. If you could then websites would be constantly sending spam adverts to your printer too.
   
Quote:
always print to server's printer

That's because VB code always runs on the Server, not the Client - so the printers it has access to are all connected to the server. It looks like it works in development because the server and the client are the same physical machine.

The server does not have any direct access to the client hardware - including any printers - for security reasons. Imagine you could: what would malicious sites do with your printer if they could access it directly?
   
Quote:
always print to server's printer

Server can't directly print on client's printer, this is a security feature.
The only possibility is if client's printer is a network printer and server on same network (company network, not internet).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900