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:
- protected void Print(object sender, EventArgs e)
- {
- ImageButton lnkRowSelection = (ImageButton)sender;
- ReportDocument cryRpt = new ReportDocument();
-
- string[] commandArgs = lnkRowSelection.CommandArgument.ToString().Split(new char[] { ',' });
- string idno = commandArgs[0];
- string company = commandArgs[1];
-
- try
- {
- if (lnkRowSelection.CommandArgument.ToString() == null)
- Response.Redirect("Default.aspx");
- else
- {
- if (company == "True")
- cryRpt.Load(Server.MapPath("~/Reports/rep1.rpt"));
- else
- cryRpt.Load(Server.MapPath("~/Reports/rep2.rpt"));
-
- if (lnkRowSelection.CommandArgument.ToString() != null)
- {
- cryRpt.SetParameterValue("@idno", idno);
- cryRpt.SetParameterValue("Office", agr.getOffice());
- cryRpt.PrintToPrinter(2, true, 1, 2);
- }
- }
- }
- catch (Exception ex) { appObj.myMessageBox(ex.Message); }
-
- }
Rep1 and rep2 were created using the report wizard.
Thank you in advance.