Save PDF file from RDLC Reports

When developer need to generate PDF file based on report without any Report viewer in UI.
Below is the code window application to generate PDF file on specific location as well as save dialog box in window or web application. (Note: This code I have added code for window application for save dialog box code).

Microsoft.Reporting.WinForms.ReportViewer reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
            Microsoft.Reporting.WinForms.LocalReport objRDLC = new Microsoft.Reporting.WinForms.LocalReport();
            reportViewer1.LocalReport.ReportEmbeddedResource = "OrderDetails.rdlc";
            ReportData oReportData = new ReportData();
            DataTable oReportDataTable = oReportData. OrderDetails (OrderID, UserID).Tables[0]; // Fetch data from database
            reportViewer1.LocalReport.EnableHyperlinks = true;
            reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", oReportDataTable));
            byte[] byteViewer = reportViewer1.LocalReport.Render("PDF");

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "*PDF files (*.pdf)|*.pdf";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                FileStream newFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                newFile.Write(byteViewer, 0, byteViewer.Length);

This code is helpfull when requirement comes for create a PDF and sent an email to specified id from RDLC reports.
Let me ask a if you need more information by adding comments.

“Enjoy Programming”
Amit Patel

About amitpatelit
Having more than 9 years of experience in IT industry. - Strong knowledge and experience on various technologies and tools like ASP.NET, MVC, Entity framework, Razor,VB.NET, C#, WCF,WPF, MVC, Silver light, ASP, XML ,Java Script, HTML, CSS, AJAX, COM/DCOM,MS SQL Server, Enterprise Library, MSMQ, SQL Server Reporting Service, Crystal Reports. - Achieved 7800 points (Star level) in the official Microsoft ASP.NET forum. - MCPD and MCTS in Web, Window and distributed application.

3 Responses to Save PDF file from RDLC Reports

  1. Nilesh says:

    it is really helpful

  2. Vince says:

    Thank you!

  3. getmscode says:

    Nice Detail description there is a similar post but easy to understand. You can see on below link

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 244 other followers

%d bloggers like this: