Question

Report viewer in .net have excellent built in export feature with support for different export formats like word , pdf and excel. For the managers in my asp application, I would however like this export functionality to generate a single export file containing multiple rdlc reports, so they can float a single document around and keep drinking coffees!. The reports that need to be exported are dynamically decided based on some business logic.
I found a useful code snippet on a forum to achieve this which Looks good:

    protected void ExportReportsToWord(object Sender, EventArgs e)
    {
        // Variables
        Warning[] warnings;
        string[] streamIds;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;

        // reportViewer1 and reportViewer2 are reports on my asp.net page
        byte[] bytes1 = reportViewer1.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
        byte[] bytes2 = reportViewer2.LocalReport.Render("WORD", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

        //create a single byte array out of multiple arrays
        byte[] bytes = (bytes2.Concat(bytes1)).ToArray();

        // Now that you have all the bytes representing the Word report, buffer it and send it to the client.
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + "singleReport" + "." + extension);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush(); // send it to the client to download
        Response.End();

    }

This code complies fine but the exported file with this code still showup only 1 report upon opening up the word document, even though the bigger file size indicates the data is probably in there for the other report too.
Can someone point out what could be the problem? I am open to suggestions on using an entirely different approach as well if it can generate a single word file export out of multiple rdlc reports.

Was it helpful?

Solution

A simple solution is to create one large Master report.

Have list inside each element of which is a sub report.

Pass parameters to the master report to decide which reports to show, and which to hide.

This way, user can choose which reports he wants to see, and you get all the features that SSRS provides for a standard report.

OTHER TIPS

Hi I would Suggest you rather have one report which then contains all these reports as child reports and then schedule that main report to be sent as email to your bosses as word document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top