Solved

programming  render and save reportviewer

Posted on 2014-03-11
4
874 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…

617 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