How to show export button in rdlc, for exporting it to Excel

Asked By 20 points N/A Posted on -
qa-featured

How to show export button in rdlc, so that i can easily export rdlc files to Excel. Please help me to find a solution.

SHARE
Best Answer by Algren Nathan
Answered By 0 points N/A #168805

How to show export button in rdlc, for exporting it to Excel

qa-featured

Hello Dustin Albas,

You can create a custom export to Excel option in RDLC. Please try the code given below that I have attached to this message it is in a Windows Notepad file, it is put together through Microsoft's documentation on Report Viewer and various google searches.

I hope this solves your issue.

Best Answer
Best Answer
Answered By 0 points N/A #168806

How to show export button in rdlc, for exporting it to Excel

qa-featured

 

 

Dear Dustin Albas,

You can export rdlc files directly to excel. There is a code behind file to do that and you even don’t need use export button. You have to use the ReportViewer .LocalReport.Render() method and specify that it is an Excel file what you want.

Here is the code:

private void CreateEXCEL(string fileName)
{
    // Variables
    Warning[] warnings;
    string[] streamIds;
    string mimeType = string.Empty;
    string encoding = string.Empty;
    string extension = string.Empty;

    // Setup the report viewer object and get the array of bytes
    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    viewer.LocalReport.ReportPath = "YourReportHere.rdlc";

    byte[] bytes = viewer.LocalReport.Render("EXCEL", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

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

 

Thank You.

Login/Register to Answer

Related Questions