Results 1 to 6 of 6

Thread: [RESOLVED] Need help with Reportviewer

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [RESOLVED] Need help with Reportviewer

    I need a code to export the data showing in my reportviewer to a .pdf file.

    can anyone help me?

  2. #2
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Need help with Reportviewer

    1.You need add reference of PDF file..

    2. Import that reference in Source code.

  3. #3
    Addicted Member
    Join Date
    Jul 2007
    Posts
    159

    Re: Need help with Reportviewer

    Add ReportViewer control to form
    Set report as your report
    Click dropdown of button with little save disk
    Select Pdf

  4. #4

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Need help with Reportviewer

    I know about the save as pdf button embedded in the reportviewer, but I need to do this with my own code.

    I did find this:
    vb.net Code:
    1. ReportViewer1.LocalReport.Render(.....

    Now I just need to figure out how it works

  5. #5
    Addicted Member
    Join Date
    Jul 2007
    Posts
    159

    Re: Need help with Reportviewer

    add these includes:
    Code:
    using System.Configuration;
    using Microsoft.Reporting.WinForms;
    using System.IO;
    on your button click event add:
    Code:
    Warning[] warnings;
    string[] streamids;
    string mimeType;
    string encoding;
    string extension;
    
    byte[] bytes = rvReport.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
    FileStream fs = new FileStream(@"c:\output.pdf", FileMode.Create);
    fs.Write(bytes, 0, bytes.Length);
    fs.Close();
    You can also change "PDF" to "EXCEL" and "output.pdf" to "output.xls" for an excel report
    You can also change "PDF" to "IMAGE" and "output.pdf" to "output.jpg" for an image report

    don't forget to catch exceptions using the try catch cos you never know
    Last edited by ^^vampire^^; Jul 20th, 2010 at 04:30 AM.

  6. #6

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Need help with Reportviewer

    I got it working like this.

    vb.net Code:
    1. Private Sub ExportRPTtoPDF(ByVal FolderLocation As String, ByVal FileName As String)
    2.         'ADD THE FOLLOWING:
    3.         '       Imports System.IO
    4.         '       Imports Microsoft.Reporting.WinForms
    5.  
    6.  
    7.         Dim warnings As Warning() = Nothing
    8.         Dim streamids As String() = Nothing
    9.         Dim mimeType As String = Nothing
    10.         Dim encoding As String = Nothing
    11.         Dim extension As String = Nothing
    12.         Dim bytes As Byte()
    13.  
    14.         'First delete existing file
    15.         Dim filepath As String = FolderLocation & "\" & FileName & ".PDF"
    16.         File.Delete(filepath)
    17.  
    18.         'Then create new pdf file
    19.         bytes = rvInv.LocalReport.Render("PDF", Nothing, mimeType, _
    20.             encoding, extension, streamids, warnings)
    21.  
    22.         Dim fs As New FileStream(FolderLocation & "\" & FileName & ".PDF", FileMode.Create)
    23.         fs.Write(bytes, 0, bytes.Length)
    24.         fs.Close()
    25.     End Sub

    Thank you for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width