 |
BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9  | This is the forum to discuss the Wrox book Professional SQL Server 2005 Reporting Services by Paul Turley, Todd Bryant, James Counihan, Dave DuVarney; ISBN: 9780764584978 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

June 20th, 2006, 01:55 PM
|
Registered User
|
|
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Render Via Binary Writer
Hello All,
I'm trying the follow the example Chpt 12, of the book Prof SQL Server 2005 Report Server, and having some problems.
When the code makes the call to the last line: Response.BinaryWrite(data), Adobe give me and error. I get a message box from IE asking if I want to Save or Open the file, I can click either, and then Adobe will through an error telling me the file is damage.
I remember in Ver2000, there was a issue with the render method, not writing the correct Binary header for Adobe, and Adobe throwing a error. The work around was to write the binary to FSO someplace a redirector could access it, and then re-render in a separate http call.
Has anyone seen this problem.
Here is my code for all to view.
Thanks,
rwiethorn
Protected Sub btnBinaryRender_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBinaryRender.Click
'Render a Report via a Binary File Stream and dispaly as a PDF
'create the Reporting Service Object
Dim RS As New ReportingService
Dim Path As String = "/PA/Misclassified"
Dim Format As String = "PDF" ' Output format of the report
'Set the Credentials to pass to the Reporting Services
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim Parameters As ReportServices.ParameterValue()
Dim Encoding As String ' Output from ReportingServer containg the encoding of th report. The encoding parameter is used to correctly decode the returned byte array.
Dim MimeType As String 'Used to render a repor to the web, passed to the Response Object to ensure that the browser correctly handles the document correctly.
Dim ParametersUsed As ParameterValue()
Dim Warnings As Warning()
Dim StreamIDs As String() ' Output of StreamID's used witht he RenderStreamID
'render the report
Dim data As Byte()
data = RS.Render(Path, Format, Nothing, Nothing, Parameters, _
Nothing, Nothing, Encoding, MimeType, ParametersUsed, _
Warnings, StreamIDs)
'Determine if the format is rendered to the web of a file
Dim Extension As String = GetExtension(MimeType)
Dim ReportName As String = Path.Substring(Path.LastIndexOf("/") + 1)
Dim FileName As String = ReportName & "." & Extension
'Write the Report to the Response Object
Response.Clear()
Response.ContentType = MimeType
'Add the filename to the response if it not a web browser format
If MimeType <> "text/html" Then
Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)
End If
Response.BinaryWrite(data)
End Sub
Public Function GetExtension(ByVal MimeType As String) As String
Dim retVal As String
Select Case MimeType
Case "text/html" 'HTML3.2, HTML 4.0
retVal = "html"
Case "multipart/related" 'MHTML
retVal = "html"
Case "text/xml" 'XML
retVal = "xml"
Case "text/plain" 'CSV
retVal = "csv"
Case "image/tiff" 'TIFF
retVal = "tif"
Case "application/pdf" 'PDF
retVal = "pdf"
Case "application/vnd.ms-excel" 'EXCEL
retVal = "excel"
End Select
Return retVal
End Function
End Class
rwiethorn
|

March 30th, 2007, 03:24 AM
|
Registered User
|
|
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Have you been able to resolve this problem? I am having the same issue.
|

March 30th, 2007, 03:25 AM
|
Registered User
|
|
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Have you been able to resolve this problem? I am having the same issue.
|

August 2nd, 2007, 02:44 AM
|
Registered User
|
|
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is my working code
----
Public Sub RenderReport()
Dim rs As New ReportExecutionService()
Dim userName As String = System.Configuration.ConfigurationManager.AppSetti ngs.Item("ReportServerUser")
Dim passWord As String = System.Configuration.ConfigurationManager.AppSetti ngs.Item("ReportServerPassword")
Dim domain As String = System.Configuration.ConfigurationManager.AppSetti ngs.Item("ReportServerDomain")
If domain Is Nothing OrElse domain.Trim = "" Then
rs.Credentials = New System.Net.NetworkCredential(userName, passWord)
Else
rs.Credentials = New System.Net.NetworkCredential(userName, passWord, domain)
End If
'rs.Url = "http://myserver/reportserver/ReportExecution2005.asmx"
rs.Url = ReportServerURL + "/ReportExecution2005.asmx"
' Render arguments
Dim result As Byte() = Nothing
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
If ReportFormat = "HTML4.0" Then
devInfo = "<DeviceInfo>"
devInfo += "<StreamRoot>/Temp/Images/</StreamRoot>"
devInfo += "<Toolbar>False</Toolbar>"
devInfo += "<Parameters>False</Parameters>"
devInfo += "<HTMLFragment>True</HTMLFragment>"
devInfo += "<StyleStream>False</StyleStream>"
devInfo += "<Section>0</Section>"
devInfo += "<Zoom>" & Request.QueryString("Zoom") & "</Zoom>"
'devInfo += "<Zoom>100</Zoom>"
devInfo += "</DeviceInfo>"
End If
Dim credentials As DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String = ""
Dim mimeType As String = ""
Dim warnings As Warning() = Nothing
Dim reportHistoryParameters As ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim execInfo As New ExecutionInfo
Dim execHeader As New ExecutionHeader()
Dim SessionId As String
Dim extension As String = ""
Dim image1 As Byte()
Dim streamid As String
Dim mTempFolder As String
rs.ExecutionHeaderValue = execHeader
execInfo = rs.LoadReport(ReportPath, historyID)
If ReportParameters Is Nothing Then
Else
rs.SetExecutionParameters(ReportParameters, "en-us")
End If
SessionId = rs.ExecutionHeaderValue.ExecutionID
Try
If ReportFormat = "HTML4.0" Then
result = rs.Render(ReportFormat, devInfo, extension, mimeType, encoding, warnings, streamIDs)
mTempFolder = System.AppDomain.CurrentDomain.BaseDirectory
mTempFolder = IO.Directory.GetParent(mTempFolder).FullName
mTempFolder = mTempFolder + "\Temp\Images\"
For Each streamid In streamIDs
image1 = rs.RenderStream(ReportFormat, streamid, devInfo, encoding, mimeType)
Dim stream As System.IO.FileStream = System.IO.File.OpenWrite(mTempFolder & streamid & ".png")
stream.Write(image1, 0, CInt(image1.Length))
stream.Close()
Next
'get the report as a string
Dim imgids As String = ""
Dim enc As System.Text.Encoding = System.Text.Encoding.UTF8
Dim tmpReport As String = enc.GetString(result)
Dim httpString As String = "http://"
If Request.Url.ToString.IndexOf("https://") >= 0 Then
httpString = "https://"
End If
'replace all occurrences of report server link with current page link
tmpReport = tmpReport.Replace(ReportServerURL.Replace("/ReportService.asmx", "?"), httpString & Request("SERVER_NAME") & Request("SCRIPT_NAME") & "?Report=")
If tmpReport.IndexOf(":auto") <> -1 Then
Dim index As Integer
index = tmpReport.IndexOf(":auto")
tmpReport = tmpReport.Substring(0, index) & ":hidden" & tmpReport.Substring(index)
End If
For Each streamid In streamIDs
If (imgids = "") Then
imgids = streamid & ".png"
Else
imgids = imgids & "," + streamid & ".png"
End If
tmpReport = tmpReport.Replace(streamid, streamid & ".png")
Next
If imgids <> "" AndAlso imgids.Length > 1 Then
ImageStreamids = imgids
'hdnRemoveImage.Value = "YES"
'hdnSiteAdd.Value = CommonFunctions.getServerAddress()
tmpReport = tmpReport.Replace("/Temp/Images/", "../Temp/Images/")
tmpReport = tmpReport.Replace("<IMG", "<IMG")
End If
ReportPlaceholder.InnerHtml = tmpReport
Return
Else
result = rs.Render(ReportFormat, devInfo, extension, mimeType, encoding, warnings, streamIDs)
End If
Response.ClearContent()
Select Case ReportFormat
Case "PDF"
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "fileattachment; filename=ST5_Report_" + System.Guid.NewGuid().ToString + ".pdf")
Case "CSV"
Response.ContentType = "application/csv"
Response.AddHeader("content-disposition", "fileattachment; filename=ST5_Report_" + System.Guid.NewGuid().ToString + ".csv")
Case "EXCEL"
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "fileattachment; filename=ST5_Report_" + System.Guid.NewGuid().ToString + ".xls")
Case "IMAGE"
Response.ContentType = "image/tiff"
Response.AddHeader("content-disposition", "fileattachment; filename=ST5_Report_" + System.Guid.NewGuid().ToString + ".tif")
Case "XML"
Response.ContentType = "text/xml"
Response.AddHeader("content-disposition", "fileattachment; filename=ST5_Report_" + System.Guid.NewGuid().ToString + ".xml")
End Select
Response.BinaryWrite(result)
Response.Flush()
Response.Close()
Catch e As System.Web.Services.Protocols.SoapException
Response.Write("An error occured while processing this report.")
Response.End()
Catch ex As Exception
Response.Write("An error occured while processing this report.")
Response.End()
End Try
End Sub
-----------
Hope this helps:)
|
|
 |