Monday, March 26, 2012

Opening a PDF report without the OPEN/Save Dialog

Is there a way to render the PDF report in the same broswer window you just called it from without the Open/Save dialog box coming up. The report is being call directly by URL parameters for PDF formatNo there is not. We set the Content-Type to attachment which causes IE to prompt for this.|||

This is quite easy with custom programming, I've made a new webapp and gave the aspnet-user full access to reporting services, maybe you could add a cutom file to the Reports-Webapp..

I've default.aspx:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Dim pdfloader As New PDFLoader(Request, Response)

and default.aspx.vb:

Public Class PDFLoader

Private request As System.Web.HttpRequest
Private response As System.Web.HttpResponse

Public Sub New(ByVal request As System.Web.HttpRequest, ByVal response As System.Web.HttpResponse)
Me.request = request
Me.response = response
End Sub

Public Sub show()
Dim rsExec As New ReportExecutionService
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials

' Prepare Render arguments
Dim historyID As String = Nothing
Dim deviceInfo As String = Nothing
Dim format As String = "PDF"
Dim showHide As String = Nothing
Dim results() As [Byte]
Dim warnings As RepExServ.Warning() = Nothing
Dim streamIDs As String() = Nothing
Dim encoding As String = String.Empty
Dim mimeType As String = String.Empty
Dim reportName As String

Dim zaehl As Integer = -1
Dim names(), name, values(), value As String
Dim ParameterValues() As RepExServ.ParameterValue
ParameterValues = New RepExServ.ParameterValue(0) {}

names = request.QueryString.AllKeys
For Each name In names
values = request.QueryString.GetValues(name)
For Each value In values
If (name = "") Then
reportName = value
zaehl = zaehl + 1
If zaehl >= ParameterValues.Length Then
ReDim Preserve ParameterValues(zaehl)
End If
Dim ParameterValue As RepExServ.ParameterValue = New RepExServ.ParameterValue
ParameterValue.Name = name
ParameterValue.Value = value
ParameterValue.Label = Nothing
ParameterValues(zaehl) = ParameterValue
End If



Dim ei As ExecutionInfo = rsExec.LoadReport(reportName, historyID)
If zaehl > -1 Then
rsExec.SetExecutionParameters(ParameterValues, "")
End If

'Exectute the report and send it to the Client
results = rsExec.Render(format, deviceInfo, "", encoding, mimeType, warnings, streamIDs)
response.ContentType = "application/pdf"

End Sub
End Class

Partial Class _Default
Inherits System.Web.UI.Page

End Class

This works just similar to the usual URL-Access method, but you can't specify any "rs:" - Parameters.. sampe call:


okay, I forgot something: you have to add WebReferences to you webapp:

|||Yes, you can always add your own web app to do this. I was stating that RS does not allow you to change this behavior using either URL access or Report Manager|||You can do this with the ReportViewer control, using the ExportContentDisposition property.|||

I also would like to open my report in PDF format without opening the Open/Save Dialog box.

I read that the ExportContentDisposition is indeed the property to use.

Is there a way to put this property in the URL when calling the report? Or do I have to use the ReportViewer Control? I am using SQL Server Reporting with ASP, not



You can always mimic the approach given above of hainvg a custom page that does the export, just recode it in ASP, rather than ASP.NET.

Hope that helps,



I have just tried creating the web app posted by BenniG and it works great on my computer but when I try from any of my co-workers computers i get a scripting error stating invalid character on line 2 character 1.

I know this is pretty vague but then again so is the error.

Any thoughts?

No comments:

Post a Comment