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);
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.