Request a topic or
contact an Arke consultant
All posts tagged 'srs'

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments




The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

Serving PDF Reports from ASP.NET using SQL Reporting Services

I recently had to create a PDF on the server-side and deliver it to the client via ASP.NET.  There are several open source PDF APIs out there so the options are vast.  But I chose to leverage SQL Reporting Services instead of learning another API.  Plus, why program a report when you can design it using proven tools?

Using SQL Server Business Intelligence Development Studio, I created a reports project, developed a report called Report1, and deployed to SQL Reporting Services.  Here is a great article if you want help creating your first report.  Tutorial: Designing Your First Report in SQL Server Reporting Services.

Next, in my ASP.NET application, I added a Web Reference to http://server/Reportserver/reportservice.asmx and named it ReportsWS, which generates all the proxy classes needed to interface with Reporting Services from my code.  Now I just have to write a little bit of code to generate the report and deliver the PDF.  In the example below, you can also see how to pass parameters to the report named StartDate and EndDate.

Using rs As New ReportsWS.ReportingService()
    rs.Credentials = New System.Net.NetworkCredential(ConfigurationManager.AppSettings("RSUser"), ConfigurationManager.AppSettings("RSPassword"), ConfigurationManager.AppSettings("RSDomain"))
Dim sReportPath As String = ConfigurationManager.AppSettings("RSReportPath")
Dim sReportName As String = "Report1"

Dim ResultStream() As Byte

Dim StreamIdentifiers() As String = Nothing

Dim optionalParams(2) As ReportsWS.ParameterValue

Dim OptionalParam As String = Nothing

Dim optionalWarnings As ReportsWS.Warning() = Nothing
optionalParams(0) = New ReportsWS.ParameterValue

optionalParams(0).Name = "StartDate"

optionalParams(0).Value = "1/1/2007"

optionalParams(1) = New ReportsWS.ParameterValue

optionalParams(1).Name = "EndDate"

optionalParams(1).Value = "12/31/2007"

' Create and set the content type string
Dim contentType As String = "application/pdf"

ResultStream = rs.Render("/" & sReportPath & "/" & sReportName, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", optionalParams, Nothing, Nothing, OptionalParam, OptionalParam, optionalParams, optionalWarnings, StreamIdentifiers)

Response.ContentType = "application/octet-stream"

Response.AddHeader("Content-Type", contentType)

Response.AddHeader("Content-Disposition", "attachment;filename=" & sReportName & ".pdf")

End Using


Posted by Eric Stoll on Wednesday, January 2, 2008 9:39 AM
Permalink | Comments (0) | Post RSSRSS comment feed