ReportViewer

G

Gerhard

I am using vb.net and asp.net version 3.5. I have a page with a ReportViewer
where I want to be able to programatically save the report in Excel format in
a specified directory on the web server. Can you please point me to sample
code on how to do this?

Thanks.
 
S

Steven Cheng [MSFT]

Hi Gerhard,

As for the Visual Studio ReportViewer control, it does support programmtic
exporting/saving the report content. Actually, it is done through the
LocalReport.Render method, this method can help you programmtically
generate the binary stream(byte array) of the report content. Here is a web
article mentioned this:

#How to render client report definition files (.rdlc) directly to the
Response stream without preview
http://weblogs.asp.net/rajbk/archive/2006/03/02/How-to-render-client-report-
definition-files-_28002E00_rdlc_2900_-directly-to-the-Response-stream-withou
t-preview.aspx

I've also written a simple example in VB.NET for your reference:

VB.NET sample
=========================

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click

Dim reportType As String = "PDF"
Dim mimeType As String
Dim encoding As String
Dim fileNameExtension As String

'The DeviceInfo settings should be changed based on the reportType
'http://msdn2.microsoft.com/en-us/library/ms155397.aspx

Dim deviceInfo As String = "<DeviceInfo>
<OutputFormat>PDF</OutputFormat>
<PageWidth>8.5in</PageWidth><PageHeight>11in</PageHeight><MarginTop>0.5in</M
arginTop><MarginLeft>1in</MarginLeft><MarginRight>1in</MarginRight><MarginBo
ttom>0.5in</MarginBottom></DeviceInfo>"

Dim warnings As Warning()
Dim streams As String()
Dim renderedBytes As Byte()


'Render the report
renderedBytes = ReportViewer1.LocalReport.Render(reportType,
deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

Dim fs As FileStream =
System.IO.File.Create("c:\temp\report_out.pdf")
fs.Write(renderedBytes, 0, renderedBytes.Length)

fs.Close()
====================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
S

Steven Cheng [MSFT]

You're welcome Gerhard,

If anything else we can help, please feel free to post in the newsgroup.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?R2VyaGFyZA==?= <[email protected]>
References: <[email protected]>
Subject: RE: ReportViewer
Date: Fri, 20 Jun 2008 08:55:01 -0700
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top