Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

programming  render and save reportviewer

Posted on 2014-03-11
4
Medium Priority
?
897 Views
Last Modified: 2014-03-17
Hello,

I'm looking to find a solution on how to programming render a report viewer document and save the document as a PDF. So far I've established this small line of code however, I'm sure there is more to it that I am missing.

ReportViewer1.LocalReport.Render

Open in new window

0
Comment
Question by:lincstech
  • 3
4 Comments
 
LVL 13

Expert Comment

by:devlab2012
ID: 39920319
Render the report into a byte arrary and then save this array into a PDF file.


Here is a code snippet for this :


String reportFormat = "PDF";

FileStream stream = null;
String filePath = "";

String mimeType;
String encoding;
String fileNameExtension;
Microsoft.Reporting.WebForms.Warning[] warnings;
String[] streamIds;

//Render the report into a byte arrary, then save this byte arrary to a file
          byte[] reportBytes = ReportViewer1.ServerReport.Render(reportFormat, null, out mimeType, out encoding, out fileNameExtension, out streamIds, out warnings);
          filePath = Server.MapPath("ReportFolder") + "/" + "MyPDFReport" + "." + fileNameExtension;
          stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
          stream.Write(reportBytes, 0, reportBytes.Length);
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 39920323
String reportFormat = "PDF";

FileStream stream = null;
String filePath = "";

String mimeType;
String encoding;
String fileNameExtension;
Microsoft.Reporting.WebForms.Warning[] warnings;
String[] streamIds;

//Render the report into a byte arrary, then save this byte arrary to a file
          byte[] reportBytes = ReportViewer1.ServerReport.Render(reportFormat, null, out mimeType, out encoding, out fileNameExtension, out streamIds, out warnings);
          filePath = Server.MapPath("ReportFolder") + "/" + "MyPDFReport" + "." + fileNameExtension;
          stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
          stream.Write(reportBytes, 0, reportBytes.Length);

Open in new window

0
 

Author Comment

by:lincstech
ID: 39920382
Is this a Visual Basic.net code or C Sharpe coding ? I'm looking for VB.net
0
 
LVL 13

Accepted Solution

by:
devlab2012 earned 2000 total points
ID: 39920468
This is a C# code. I am not into VB.NET programming, but can try to write the code in VB.NET:

       
 Dim reportFormat as String
        reportFormat = "PDF"

        Dim stream as FileStream
        stream = null
        Dim filePath as String
        filePath = ""

        Dim mimeType as String
        Dim encoding as String
        Dim fileNameExtension as String
        Dim warnings as Microsoft.Reporting.WebForms.Warning()
        Dim streamIds as String

        'Render the report into a byte arrary, then save this byte arrary to a file
        Dim reportBytes as Byte()
        reportBytes = ReportViewer1.ServerReport.Render (reportFormat, nothing, mimeType, encoding, fileNameExtension, streamIds, warnings)
        filePath = Server.MapPath("ReportFolder") + "/" + "MyPDFReport" + "." + fileNameExtension
        stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create)
        stream.Write(reportBytes, 0, reportBytes.Length)

Open in new window

0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question