Solved

programming  render and save reportviewer

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

This article describes some very basic things about SQL Server filegroups.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

773 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