Exporting reporting programmatically RRS feed

  • Question

  • Is there a way to export report (rdlc) programmatically from the application? The ReportViewer control provides export ability on runtime, but I could not find any method in ReportViewer object model.


    -= JL =-
    Wednesday, February 25, 2009 6:32 AM

All replies

  • Yes.  Depending on the mode you are using, call ReportViewer.ServerReport.Render() or ReportViewer.LocalReport.Render().  You can get the list of available formats from the report objects ListRenderingExtensions() method.
    Wednesday, February 25, 2009 6:46 AM
  • Hi Brian

    Thanks for you reply it was really helpful. I have another question though. The Render() method save the report in the specified format to the disk. Is there a way to open the exported report. For instance if I render my report as Excel, I want the rendered report to open in Excel rather than saved to the disk.

    The Web ReportViewer control has a ExportContentDisposition property that can be set to AlwaysInLine to open the report in the brower. I could not find anything similar for win reportviewer control.


    -= JL =-
    Wednesday, February 25, 2009 1:32 PM
  • The Render method does not save the report to disk.  It returns a byte array that you can use any way you want.  If you save that byte array to disk, you should be able to launch Excel and point it at that file.
    Wednesday, February 25, 2009 9:10 PM
  • Hi Brian

    This is what I do to save the file to disk

    byte[] bytes = reportViewer1.LocalReport.Render("Excel", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);


    using (FileStream fs = new FileStream(@"c:\temp\output.xls", FileMode.Create))


        fs.Write(bytes, 0, bytes.Length);



    Is there a way to open byte array in excel without saving the file on to the disk. I have peculiar requirement where the client doesn't want the file to be saved to the disk.

    -= JL =-
    Thursday, February 26, 2009 4:45 AM