Sat. Mar 28th, 2020

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 ASP.net & 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 ASP.net 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

Copyright © All rights reserved. | Newsphere by AF themes.
Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.