Click here to Skip to main content
13,140,591 members (47,200 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 4 Jul 2011

Exporting a SQL Server Reporting Services 2005 Report Directly to PDF or Excel

, 4 Jul 2011
Rate this:
Please Sign up or sign in to vote.
How to export a SQL Server Reporting Services 2005 report directly to PDF or Excel.

Exporting a SQL Server Reporting Services 2005 (SSRS) Report Directly to PDF/Excel is a handy way of generating high quality reports without being stuck to using the ReportViewer interface. Sometimes the ReportViewer interface is an unnecessary step, but other times the ReportViewer won't render correctly even though the underlying report is correct. This is especially true when your audience might use Firefox or Safari (or anything other than IE), since the ReportViewer control almost never outputs a readable report. Of course, it would be nice to just have a button on your page that generates a PDF or Excel file in any browser, and uses an SSRS back-end to do all of the report creating and heavy lifting.

The following code will show how to export such a report, including the passing of an arbitrary number of custom parameters. Note that the identity of the application pool that your website runs under will need to have at least "browser" access to the folder containing the report you want to display. This is usually pretty simple if both IIS and SSRS server are within the same domain, but it might be tricky if this is not the case.

Microsoft.Reporting.WebForms.ReportViewer rview = new Microsoft.Reporting.WebForms.ReportViewer();
//Web Address of your report server (ex: http://rserver/reportserver)
rview.ServerReport.ReportServerUrl = new Uri(WebConfigurationManager.AppSettings["ReportServer"]); System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter> paramList = 
  new System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter>();
paramList.Add(new Microsoft.Reporting.WebForms.ReportParameter("Param1″, "Value1″));
paramList.Add(new Microsoft.Reporting.WebForms.ReportParameter("Param2″, "Value2″));
rview.ServerReport.ReportPath = "/ReportFolder/ReportName";
string mimeType, encoding, extension, deviceInfo;
string[] streamids;Microsoft.Reporting.WebForms.Warning[] warnings;
string format = "PDF"; //Desired format goes here (PDF, Excel, or Image)
deviceInfo = "<DeviceInfo>" +"<SimplePageHeaders>True</SimplePageHeaders>" +
byte[] bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, 
               out encoding, out extension, out streamids, out warnings);
if (format == "PDF")
  Response.ContentType = "application/pdf";
  Response.AddHeader("Content-disposition", "filename=output.pdf");
else if (format == "Excel")
  Response.ContentType = "application/excel";
  Response.AddHeader("Content-disposition", "filename=output.xls");
Response.OutputStream.Write(bytes, 0, bytes.Length);

One potential issue that you might run into upon deploying your project is that your application server may not have the ReportViewer DLLs that are needed. You have two options in this case. The first is to copy the three Microsoft.ReportViewer.*.dll's (ReportViewer.Common.dll, ReportViewer.ProcessingObjectModel.dll, and ReportViewer.WebForms.dll) from your development computer into the BIN folder of your application server (or into the GAC). The second option (though I have not verified it) is to install the SSRS redistributable on the application server (

Check out for good SSRS resources, including some nice learning tools and report packs.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nicky Enriquez Torres
Web Developer Telefonica del Peru
Peru Peru
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 4 Jul 2011
Article Copyright 2011 by Nicky Enriquez Torres
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid