Solved

programming  render and save reportviewer

Posted on 2014-03-11
4
819 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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now