Tuesday, June 29, 2010

#002 Render ReportViewer as PDF

If you want to programatically save a Microsoft.Reporting.WinForms.ReportViewer as a PDF to the filesystem or a database, the Render(...) Method will help you out by returning a byte array of the rendered file content.

Here is the code snippet:


   1:  byte[] fileData = null;
   2:  Warning[] warnings;
   3:  string[] streamids;
   4:  string mimeType;
   5:  string encoding;
   6:  string extension;
   7:   
   8:  fileData = reportViewer.LocalReport.Render(
   9:   "PDF", null, out mimeType, out encoding,
  10:    out extension,
  11:   out streamids, out warnings);