Chriz L

Chriz L

  • NA
  • 220
  • 49.1k

Crystal report automatically send to clients default printer

Nov 14 2016 5:56 AM
Hello,
 
I need to be able to print a report automatically on client's local printer( some printers are on the same network and some others are usb-connected) .
I don't want to open the report in viewer before printing. 
 
Here's my code: 
  1. protected void Print(object sender, EventArgs e)      
  2.        {      
  3.            ImageButton lnkRowSelection = (ImageButton)sender;      
  4.            ReportDocument cryRpt = new ReportDocument();      
  5.       
  6.            string[] commandArgs = lnkRowSelection.CommandArgument.ToString().Split(new char[] { ',' });      
  7.            string idno = commandArgs[0];      
  8.            string company = commandArgs[1];      
  9.       
  10.            try      
  11.            {      
  12.                if (lnkRowSelection.CommandArgument.ToString() == null)      
  13.                    Response.Redirect("Default.aspx");      
  14.                else      
  15.                {      
  16.                    if (company == "True")      
  17.                        cryRpt.Load(Server.MapPath("~/Reports/rep1.rpt"));      
  18.                    else      
  19.                        cryRpt.Load(Server.MapPath("~/Reports/rep2.rpt"));      
  20.       
  21.                    if (lnkRowSelection.CommandArgument.ToString() != null)      
  22.                    {      
  23.                        cryRpt.SetParameterValue("@idno", idno);      
  24.                        cryRpt.SetParameterValue("Office", agr.getOffice());      
  25.                        cryRpt.PrintToPrinter(2, true, 1, 2);       
  26.                    }      
  27.                }      
  28.            }      
  29.            catch (Exception ex) { appObj.myMessageBox(ex.Message); }      
  30.       
  31.        }   
 Rep1 and rep2 were created using the report wizard.
 
Thank you in advance.

Answers (6)