ReportViewer

Discussion in 'ASP .Net Web Controls' started by Gerhard, Jun 19, 2008.

  1. Gerhard

    Gerhard Guest

    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.
     
    Gerhard, Jun 19, 2008
    #1
    1. Advertising

  2. 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:
    .

    ==================================================
    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.


    --------------------
    >From: =?Utf-8?B?R2VyaGFyZA==?= <>
    >Subject: ReportViewer
    >Date: Thu, 19 Jun 2008 15:39:03 -0700
    >
    >
    >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.
    >
     
    Steven Cheng [MSFT], Jun 20, 2008
    #2
    1. Advertising

  3. Gerhard

    Gerhard Guest

    Awesome service. This was exactly what I needed to know.

    Thanks.

    "Steven Cheng [MSFT]" wrote:

    > 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:
    > .
    >
    > ==================================================
    > 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.
    >
    >
    > --------------------
    > >From: =?Utf-8?B?R2VyaGFyZA==?= <>
    > >Subject: ReportViewer
    > >Date: Thu, 19 Jun 2008 15:39:03 -0700
    > >
    > >
    > >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.
    > >

    >
    >
     
    Gerhard, Jun 20, 2008
    #3
  4. 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:
    .

    ==================================================
    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==?= <>
    >References: <>

    <>
    >Subject: RE: ReportViewer
    >Date: Fri, 20 Jun 2008 08:55:01 -0700


    >
    >Awesome service. This was exactly what I needed to know.
    >
    >Thanks.
    >
    >"Steven Cheng [MSFT]" wrote:
    >
    >> 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:
    >> .
    >>
    >> ==================================================
    >> 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.
    >>
    >>
    >> --------------------
    >> >From: =?Utf-8?B?R2VyaGFyZA==?= <>
    >> >Subject: ReportViewer
    >> >Date: Thu, 19 Jun 2008 15:39:03 -0700
    >> >
    >> >
    >> >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.
    >> >

    >>
    >>

    >
     
    Steven Cheng [MSFT], Jun 23, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo

    Re: dropdown overlaps reportviewer in IE

    S. Justin Gengo, Jul 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    462
    S. Justin Gengo
    Jul 31, 2004
  2. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Microsoft.ReportViewer.WebForms assembly

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Jul 4, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    949
    =?Utf-8?B?Sm9obiBCYWlsZXk=?=
    Jul 4, 2005
  3. Chris Botha

    ReportViewer problem after deploy

    Chris Botha, Nov 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,084
    Chris Botha
    Nov 16, 2005
  4. Jéjé
    Replies:
    1
    Views:
    3,677
    3cMaverick
    May 12, 2006
  5. Greg
    Replies:
    7
    Views:
    780
    Bruce L-C [MVP]
    Nov 22, 2005
Loading...

Share This Page