DonMax
DonMax

Reputation: 960

Export SSRS report directly without rendering it on ReportViewer

I have a set of RDL reports hosted on the report server instance. Some of the report renders more than 100,000 records on the ReportViewer. So that it takes quite long time to render it on the Viewer. So, we decided to go with Export the content directly from the server based on the user input parameters for the report as well as export file format.

Main thing here, I do not want the user to wait until the export file available for download. Rather, User can submit the action and can proceed to do other works. In the background, the program has to export the file to some physical location. When the download will be available, the user will be informed with some notification about the exported file.

I found the way in this Link. I need to know what are the ways to achieve the above mentioned functionality as well as how to pass the input parameters for the report. Pl suggest me.

Note: I was using XML as datasource for the rdl reports.

EDIT

I found something useful and did the coding like the below,

string path = ServerURL +"?" + _reportFolder + "ReportName&rs:Command=Render&rs:Format=PDF";
                WebRequest req = WebRequest.Create(path);
                string reportParametersQT = String.Empty;
                req.Credentials = CredentialCache.DefaultNetworkCredentials;

                WebResponse response = req.GetResponse();
                Stream stream = response.GetResponseStream();
                //screen.Response.Clear();
                string enCodeFileName = HttpUtility.UrlEncode("fileName.pdf", System.Text.Encoding.UTF8);

                // The word attachment in Addheader is used to directly show the save dialog box in browser
                Response.AddHeader("content-disposition", "attachment; filename=" + enCodeFileName);
                Response.BufferOutput = false;   // to prevent buffering
                Response.ContentType = response.ContentType;
                byte[] buffer = new byte[1024];
                int bytesRead = 0;
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Response.OutputStream.Write(buffer, 0, bytesRead);
                }
                Response.End();

I am able to download the exported file. But need to save the file in physical location instead of downloading. I dont know how to do that.

Upvotes: 1

Views: 5101

Answers (1)

Dan Scally
Dan Scally

Reputation: 2042

Both of these are very easy to do. You essentially just pass the parameters in the URL that you're calling, for example for a parameter called "LearnerList" you add &LearnerList=12345 to the URL. For exporting, add an additional paramter for Format=PDF (or whatever you want the file as) to get the report to export as a PDF instead of generating in Report Viewer.

Here's an example URL:

https://reporting.MySite.net/ReportServer/Pages/ReportViewer.aspx?/Users+Folders/User/My+Reports/Learner+Details&rs:Format=PDF&LearnerList=202307

Read these two pages, and you should be golden:

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

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

Upvotes: 1

Related Questions