Solved

programming  render and save reportviewer

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

930 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

9 Experts available now in Live!

Get 1:1 Help Now