How to export SSRS report directly to csv without rendering

I have a very large rdl report, about 50 columns and 500,000 rows. The SQL procedure behind the report is a normal selection * from a table. It only takes a few seconds to complete. However, when I want to do this report in SSRS, it takes too long.

The end user only wants to export this report to csv. It doesn't need SSRS to provide the report. Is there a way to set the default rendering mode for the report in csv. Then when the user runs it, the report will automatically ask it to save to .csv without rendering?

+3


source to share


2 answers


The easiest way is to use url access by specifying &rs:command=render&rs:format=csv

Another method is to use the API - I guess it depends on which one you like the most.



See https://msdn.microsoft.com/en-us/library/ms152835.aspx

+5


source


You can use the LocalReport.Render method to get the [] bytes from the report on page load directly, and then export it as csv:



Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
        this.ReportViewer1.LocalReport.ReportPath = 
           @"c:\Reports\Report1.rdl";
        ReportViewer1.LocalReport.DataSources.Add(
           new ReportDataSource("Test", LoadSalesData()));


byte[] bytes = reportViewer.LocalReport.Render(
    "CSV", null, out mimeType, out encoding, out filenameExtension,
    out streamids, out warnings);

Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".csv");
Response.BinaryWrite(bytes); // create the file
Response.Flush(); 

      

0


source







All Articles