Post by MacUserCan you let me know how I can get the File Save prompt without popping up a
blank browser window."
Thanks in Advance
Post by RowenPost by Chris G.One last question...how many hours of work would you estimate that it took
you to implement your custom report parameter page solution (R&D, design,
implementation and testing)?
I'm not sure I can be much help to you here... This was only a small
part of the project I was working on and it developed as the project
went on, so I cant split it out say accurately. As a rough estimate I
would say it took about 1 - 2 weeks effort for the reporting interface
requirements.
I redirect to a page that is capable of displaying a html report, or
downloading the report as a file, depending on the parameters passed
in.
On page load, I call the function ShowReport which looks like this:
Private Sub ShowReport()
' get the report path from the querystring
Dim reportPath As String = Request.QueryString("ReportPath")
Dim format As String = Request.QueryString ("ReportFormat")
Dim result As Byte() = Nothing
' get the report parameters and match up the values using
querystring values
'' retrieve all parameters
Dim parameters As New ReportParameterDataEntityCollection
For Each parameter As String In Request.QueryString
If Not (parameter.Equals("ReportPath") Or
parameter.Equals("ReportFormat")) Then
Dim objParameter As New ReportParameterDataEntity
objParameter.Name = parameter
objParameter.Value = Request.QueryString(parameter)
parameters.add(objParameter)
End If
Next
' use report manager
Dim ReportManager As IReportManager
ReportManager =
RemotingHelper.GetObject(GetType(IReportManager))
result = ReportManager.GenerateReport(Me.ActiveUserID,
reportPath, parameters, format)
Select Case format.ToUpper
Case "HTML4.0", "HTML3.2"
Dim reportContent As String =
System.Text.Encoding.UTF8.GetString(result)
litReportDetails.Text = reportContent
litPrintReportDetails.Text = reportContent
Case "PDF"
Dim fileName As String
fileName = reportPath.Substring(reportPath.LastIndexOf
("/") + 1, reportPath.Length - reportPath.LastIndexOf("/") - 1)
fileName = fileName & Now.ToString("ddMMyyyy-HHmmss")
& ".pdf"
DownloadFile(fileName, result)
Case "EXCEL"
Dim fileName As String
fileName =
reportPath.Substring(reportPath.LastIndexOf("/") + 1,
reportPath.Length - reportPath.LastIndexOf ("/") - 1)
fileName = fileName & Now.ToString("ddMMyyyy-HHmmss")
& ".xls"
DownloadFile(fileName, result)
Case "CSV"
Dim fileName As String
fileName =
reportPath.Substring(reportPath.LastIndexOf("/") + 1,
reportPath.Length - reportPath.LastIndexOf("/") - 1)
fileName = fileName & Now.ToString("ddMMyyyy-HHmmss")
& ".csv"
DownloadFile(fileName, result)
End Select
End Sub
Private Sub DownloadFile(ByVal FileName As String, ByRef b As
Byte())
Response.ClearHeaders()
Response.Clear()
' The first header ensures that the file name
' is correct on the client side. This is extremely important!
If you
' don't add this header, the browser will make
' some sort of arbitrary decision as to what the file should
be called.
' It will either offer no name and force the user to select a
name
' (As we all know, this is like giving a two-year-old a loaded
gun)
' or it will simply name the file after the web page
' it's calling (eg. MyFileServer.aspx). This will save without
any problem
' but when the user tries to open the file, their system
' will tell them it doesn't know what to do with a *.aspx file
' and you're going to slowly go insane over the next
' six months with support calls, trying to explain to users
how to
' change the file extension from *.aspx to *.pdf on their
system
Response.AddHeader("Content-disposition", "attachment;
filename=" & FileName)
' Next, we need to tell the browser what type of content
' we're serving.
' I'm using a standard application/octet-stream content type.
' It's better to find out exactly what MIME type your
particular
' file extension is defined under, as this should produce
' better browser behaviour.
' However, for our purposes, this will work just fine
' This header tells the browser that it is serving
' an application file as a byte stream.
' The browser will know immediately
' that it shouldn't serve this file as text and will open
' the File Download box instead,
' in which it offers the user the ability to save
' the file. It will also use the Content-disposition header
' (see above) to auto-populate
' the Save File dialog box with the file's name
Response.ContentType = "application/octet-stream"
' Now our headers are added, we can serve the content.
' To do this, we use the BinaryWrite() method of the server
object
' This successfully streams our external file to the user,
' despite the fact that the file doesn't exist
' anywhere inside the web application
Response.BinaryWrite(b)
' Call Response.End() so that no more
' content goes through to the client.
' The file has been downloaded,
' but if this method is not called, the page
' will continue downloading any remaining
' html/ text content and mess up the resulting stream.
' This method call ensures that the downloaded
' file doesn't end up corrupted with unwanted data
Response.End()
End Sub
I pass in parameters as name value pairs in the querystring.
ReportManager.GenerateReport is a wraper to the reporting services web
service which returns the report as a byte array.
This has been tested in IE only.
Hope this helps,
Rowen