I have created several embedded ReportViewer reports in asp.net
2.0 (using VB). Love the ReportViewer. Used Cognos SDK up to 3 wks ago,
but not any more!
When my app's user pushes a button, 8 diferent reports come up in
separate browser windows (e.g.
Response.Write("<script>window.open('../Reports/rptOversale_Compare.aspx
','_OverSaleCompare');</script>")).
What I want to do is have the reports come up in pdf format. Is this
possible The ideal objective for this app would be to have the 8
reports come up as pdf inside a tab control, but I can't find any code
or direction anywhere on how to programmatically spit out pdf instead of
ReportViewer default display. I'll worry about the tab part after getting pdf to come up.
Does anyone have any code or insight that would accomplish this Thank you for any help!!
2.0 (using VB). Love the ReportViewer. Used Cognos SDK up to 3 wks ago,
but not any more!
When my app's user pushes a button, 8 diferent reports come up in
separate browser windows (e.g.
Response.Write("<script>window.open('../Reports/rptOversale_Compare.aspx
','_OverSaleCompare');</script>")).
What I want to do is have the reports come up in pdf format. Is this
possible The ideal objective for this app would be to have the 8
reports come up as pdf inside a tab control, but I can't find any code
or direction anywhere on how to programmatically spit out pdf instead of
ReportViewer default display. I'll worry about the tab part after getting pdf to come up.
Does anyone have any code or insight that would accomplish this Thank you for any help!!

Programattically render pdf from ReportViewer
Tuoski
SmitsDJ
I'm using this:
Response.Write(
"<script>window.open('../ReportOutput/PCSummary.PDF','_PCSummary');</script>")Anyone know the difference is between this and the Response.WriteFile approach. Maybe the new browser window. Paully - any thoughts
TOP1411
Adnan -
Wow, thank you very much for this code!
I'm sorry, I forgot to mention I'm not using Reporting Svcs; ReportViewer is in local mode and I doubt the group that supports the database server has any plans to upgrade to SQL Server 2005 w/Reporting Svcs.
Is this a deal killer then for being able to do this with all Microsoft technology
Any feel for 3rd party products I might be able to use
Thanks again!
James_AeroAvi
snickers_kin
Bryn Kaufman
Yes, this works perfectly. Thank you very much!! For others, here are the details:
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 bytes As Byte()
'Get folder on web server from web.config
Dim FolderLocation As String
FolderLocation = System.Configuration.ConfigurationManager.AppSettings("ReportOutputPath")
'First delete existing file
Dim filepath As String = FolderLocation & "PCSummary.PDF"
File.Delete(filepath)
'Then create new pdf file
bytes = ReportViewer1.LocalReport.Render("PDF", Nothing, mimeType, _
encoding, extension, streamids, warnings)
Dim fs As New FileStream(FolderLocation & "PCSummary.PDF", FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
hypersw
Using a Windows Forms application...
1. Import the System.Diagnostics namespace.
2. After your fs.Close() type the following...
Process.Start(FolderLocation & "PCSummary.PDF")
Using ASP.Net (Courtesy of http://support.microsoft.com/default.aspx scid=kb;en-us;q307603)...
'Set the appropriate ContentType.
Response.ContentType = "Application/pdf"
'Get the physical path to the file.
Dim FilePath As String = FolderLocation & "PCSummary.PDF"
'Write the file directly to the HTTP output stream.
Response.WriteFile(FilePath)
Response.End()
Pivinski
Yi Liang
Thank you very much for this code - How would i wire this up to a button command so that when clicked - the pdf report is created as above, then rendered by browser. In .Net-1.1 i used a ReportServer and my button simply called the render.PDF command - and the user was prompted to download or open the PDF
Thanks Again
Derek Comingore - RSC
The Response.Write approach renders the output to pdf in the same browser window. Also works great. Here's a full copy of my code:
Imports
System.IOImports
Microsoft.Reporting.WebFormsPartial
Class Reports_rpt_PCSumByMerchant Inherits System.Web.UI.Page Protected Sub Page_SaveStateComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SaveStateComplete 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 bytes As Byte()
'Get folder on web server from web.config Dim FolderLocation As StringFolderLocation = System.Configuration.ConfigurationManager.AppSettings(
"ReportOutputPath") 'First delete existing file Dim filepath As String = FolderLocation & "PCSumByMerchant.PDF"File.Delete(filepath)
'Then create new pdf filebytes = ReportViewer1.LocalReport.Render(
"PDF", Nothing, mimeType, encoding, extension, streamids, warnings) Dim fs As New FileStream(FolderLocation & "PCSumByMerchant.PDF", FileMode.Create)fs.Write(bytes, 0, bytes.Length)
fs.Close()
'####Paully's code
'Set the appropriate ContentType.
Response.ContentType =
"Application/pdf" 'Write the file directly to the HTTP output stream.Response.WriteFile(filepath)
Response.End()
End SubEnd
ClassJohn Mandia
will try that - thanks
Paully - This is a web application - thanks again
Gr&#233;goire de Jabrun
In ASP.NET YOu can just send to the browser
myBytes = ReportViewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment; filename=myfile." + extension)
Response.BinaryWrite(myBytes)
Response.Flush()
Response.End()
vcspec
JWill
Yes, assuming you are using Reporting Services to serve up the report to start with. The process involves calling the report server and streaming the resulting report via HttpWebResponse. Setting the response content type to pdf will stream the pdf to the users browser window, and open the document as a pdf document.
The following is curtousy of Adnan Masood's blog at http://www.axisebusiness.com/adnano/PermaLink,guid,4f0b053f-2c4b-499a-8913-72b7220a6f71.aspx
Hope this helps