Close this search box.

Generating a PDF from Reporting Services without the Report Viewer

This post is primarily for Steve since he has been bugging me about it.  (Forgive the VB, but this is what I did the demos in).  Steve doesn’t like doing SQLRS, but personally, I’d like to do more of it.  I just can’t seem to come up with any clients that want to do it.

Any way, here is the process of creating the PDF without using the Report Viewer.

Create a reference to the Reporting Services Web Services then get a variable reference for it:

Dim ws As New SQLRS.ReportingService
Dim creds As New System.Net.NetworkCredential

Next set the authentication for the web service:

creds.UserName = "RSUser"
creds.Password = "SomePassword"
ws.Credentials = creds

Finally, set some of the web service variables for how you want the data rendered.  You don’t have to set all of these, but you will have to pass them all in, so I just like to be clear about what I am doing:

Dim result() As Byte
Dim report As String = "/Sample Reports/Sales Order Detail"
Dim format As String = "PDF"
Dim historyid As String = Nothing
Dim devinfo As String = ""
Dim credentials() As SQLRS.DataSourceCredentials = Nothing
Dim showhide As String = Nothing
Dim encoding As String
Dim mimetype As String
Dim warnings() As SQLRS.Warning = Nothing
Dim reporthistoryparams As SQLRS.ParameterValue() = Nothing
Dim streamid() As String = Nothing
Dim sh As New SQLRS.SessionHeader
ws.SessionHeaderValue = sh

Next, get the result from the web service:

result = ws.Render(report, format, historyid, devinfo, parameters, _
            credentials, showhide, encoding, mimetype, reporthistoryparams, _
            warnings, streamid)

And stuff it into the workflow (in this case, open the PDF in your favorite browser):

Response.ContentType = "application/pdf"

And for the record Steve…No, I will not convert this to C# for you, and I feel no shame to post VB code.

This article is part of the GWB Archives. Original Author: Brian Sherwin

Related Posts