Saturday, 19 October 2019

PrintReport in asp.net

public void PrintReport(string printerIP, string printerName)
        {
            string printerFullName = CheckPrinterConfiguration(printerIP, printerName);

            if (!string.IsNullOrEmpty(printerFullName))
            {
                //create Report Document
                ReportDocument report = new ReportDocument();

                //get report path
                string reportFilePath = Path.Combine(Environment.CurrentDirectory,
                                        "Reports\\" + rptParam.ReportParameter.ReportName + ".rpt");
                report.Load(reportFilePath);

                //set datasource to report
                report.SetDataSource(data);

                //set Printer name to report
                report.PrintOptions.PrinterName = printerName;

                System.Drawing.Printing.PageSettings page = new System.Drawing.Printing.PageSettings();

                try
                {
                    //print the report
                    report.PrintToPrinter(1, true, 0, 0);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                Console.WriteLine("Printer is not configured with IP: {0}
                and Name: {1}", printerIP, printerName);
            }
        }

No comments:

Post a Comment