Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While publishing below code in server system. in local machine while taking print its showing error message"System.Drawing.Printing.InvalidPrinterException: No printers are installed in server system".


C#
public void print()
{
    SC.Open();
    SqlCommand cmd = new SqlCommand("select * from converstion where status='A'", SC);
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    DataTable datatable = new DataTable();
    da.Fill(datatable);
    ReportDocument crreport = new ReportDocument();
    crreport.Load(Server.MapPath("~/Conversion.rpt"));       crreport.SetDataSource(datatable);
    crreport.PrintToPrinter(1, false, 0, 0);
    SC.Close();
}
Posted
Updated 15-Jun-15 22:43pm
v2
Comments
Kornfeld Eliyahu Peter 16-Jun-15 4:46am    
And? It is very common that servers have no printer attached to, but it is not a coding problem! No code in the world will be able to print on a non-existing printer!

1 solution

It means no printers are installed. Your code is running on the server, so it is trying to print on the server. You can't print on the client from server code.
 
Share this answer
 
Comments
F-ES Sitecore 16-Jun-15 5:22am    
The account your server code is running under won't have access to the printer, you'd need to make your code run under an account that does by changing the anonymous user.

However that's not going to solve your immediate problem, you can't print to the client from your server code unless the server can access the printer on the client over the network.
F-ES Sitecore 16-Jun-15 5:30am    
What you want to do isn't possible. Give the client a link to where they can download\view the file\report and the client will print the file if they want to.

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