Introduction
In my previous article I described how to create a RDLC report.
Now I show how to save a RDLC report as a PDF at run time.
I am creating a method for that named "SAVEPDF" with the two arguments:
- Path (Location) as string type where we want to save that PDF file.
Example: C:\MyFile\
- Another is ReportViewer that is the instance of the ReportViewer Class
On which we will perform the action to convert the report to a PDF; but not just PDF, we can save the file in another format, such as Word or Excel.
Here is the sample code:
- public void SavePDF(ReportViewer viewer, string savePath)
-
- {
- byte[] Bytes = viewer.LocalReport.Render(format:"PDF",deviceInfo:"");
-
- using (FileStream stream = new FileStream(savePath, FileMode.Create))
- {
- stream.Write(Bytes, 0, Bytes.Length);
- }
- }
We can save the RDLC report in another format like Word or Excel; not just in PDF.