Wed. Nov 13th, 2019

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

Generate a PDF from the Report Viewer (Web Form), in & C#

In this article, I will share with you a simple way of generating a pdf from the report viewer. Assuming you have created your .RDLC and used it in an page, users could click on the export form from the report viewer which will allow them to expert the rendered report to an Excel, PDF or Word Document. However, if you want to generate the pdf and save it locally in the code behind using C#, you can use this simple snippet:

Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
string FilePath = Server.MapPath("/data/");
FilePath +=  "ReportName.pdf";
using (FileStream fs = new FileStream(FilePath, FileMode.Create))
  fs.Write(bytes, 0, bytes.Length);

Leave a comment

Show Buttons
Hide Buttons
%d bloggers like this: