|
-
Jul 20th, 2010, 02:16 AM
#1
Thread Starter
Addicted Member
[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?
-
Jul 20th, 2010, 03:11 AM
#2
Lively Member
Re: Need help with Reportviewer
1.You need add reference of PDF file..
2. Import that reference in Source code.
-
Jul 20th, 2010, 03:52 AM
#3
Addicted Member
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
-
Jul 20th, 2010, 03:57 AM
#4
Thread Starter
Addicted Member
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:
ReportViewer1.LocalReport.Render(.....
Now I just need to figure out how it works
-
Jul 20th, 2010, 04:24 AM
#5
Addicted Member
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.
-
Jul 20th, 2010, 04:28 AM
#6
Thread Starter
Addicted Member
Re: Need help with Reportviewer
I got it working like this.
vb.net Code:
Private Sub ExportRPTtoPDF(ByVal FolderLocation As String, ByVal FileName As String) 'ADD THE FOLLOWING: ' Imports System.IO ' Imports Microsoft.Reporting.WinForms 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() 'First delete existing file Dim filepath As String = FolderLocation & "\" & FileName & ".PDF" File.Delete(filepath) 'Then create new pdf file bytes = rvInv.LocalReport.Render("PDF", Nothing, mimeType, _ encoding, extension, streamids, warnings) Dim fs As New FileStream(FolderLocation & "\" & FileName & ".PDF", FileMode.Create) fs.Write(bytes, 0, bytes.Length) fs.Close() 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|