Last post May 09, 2017 12:20 PM by Rusty1968
May 08, 2017 01:35 PM|Rusty1968|LINK
OK, I have a report where in code, I click on a button, I kick off the report and have it export automatically to pdf. I has been working fine but I had to add a second optional parameter and now the report works fine for some data but other times it runs
and then when I try to download the pdf I get the message that Adobe Acrobat reader can't open the pdf since it is either not a supported file type or because the file has been damaged. If I run the report from within SSRS it will work and randomly it will
work from with the application. I have tried changing the properties of the optional parameter inside the report and I have tried making the file name a random string to see if there was some sort of file.
Below is my code for kicking off the report. Please offer any suggestions.
ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
ReportViewer1.ServerReport.ReportServerUrl = New Uri(ReportServerURL)
ReportViewer1.ServerReport.ReportPath = ReportServerPath
Dim paramList As New Generic.List(Of ReportParameter)
Dim pInfo As ReportParameterInfoCollection
pInfo = ReportViewer1.ServerReport.GetParameters()
paramList.Add(New ReportParameter("paraPM_ID", Session("PM_ID").ToString(), True))
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim deviceInfo As String
Dim bytes As Byte()
Dim fileName As String = "Post_Mortem_Single_" + Session("PM_ID") + ".pdf"
Dim basePath As String = HttpContext.Current.Server.MapPath("~/App_Data")
deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = ReportViewer1.ServerReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
Dim fs As New FileStream(basePath & "/" + fileName, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
Response.AddHeader("content-disposition", "attachment;filename=" + fileName)
Response.Charset = ""
Response.ContentType = "application/vnd.text"
Response.TransmitFile(basePath & "/" + fileName)
May 09, 2017 07:28 AM|Chris Zhao|LINK
Try adding Response.End(). When you fail to call Response.End(), the web form appends it's HTML markup to the PDF output stream and corrupts the document.
May 09, 2017 12:20 PM|Rusty1968|LINK
It strange thing. I started yesterday by creating a new page which I linked from the original. I had that going inline instead of attachment. When I added the line to that code. it worked. but when I added to the original code which is a copy it doesn't.
I will keep looking into fixing the original page but if worse comes to worse I have something that will work.