Monday, 6 June 2016

Direct PDF Print through RDLC Report

Direct PDF Print through RDLC Report

            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;

            ReportViewer1.LocalReport.ReportPath=Server.MapPath("InvoiceReport.rdlc");
            ReportViewer1.LocalReport.SetParameters(repParamHeader);
            ReportViewer1.LocalReport.DataSources.Add(datasource);
            byte[] bytes =ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
            Response.Buffer=true;
            Response.Clear();
            //string reportPath = Path.Combine(exeFolder, @"rdlcReports\myReportName.rdlc");
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment; filename= filename" + "." + extension);
            Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file 
            Response.Flush(); // send it to the client to download 
            Response.End();

No comments:

Post a Comment