1

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.

Community
  • 1
  • 1
DonMax
  • 970
  • 3
  • 12
  • 47
  • Is the client a Web browser? Is the physical location accessible to the server and the user? – Tom Blodget May 30 '15 at 21:47
  • Yes it is a Web Browser, accessible to the server as well as user. Basically, User will be sending the export report request and can continue work on other tasks and in other form, I need to show the progress of all export activities of that specific user. – DonMax Jun 01 '15 at 03:53
  • Web browsers that write to the user's file space at the behest of an arbitrary web page are a security issue (IE4 et al). One way around that is a browser extension. Another is for the user to run a program you write instead of a web browser. Another is for the server to write the file to a network location that the user can access. – Tom Blodget Jun 01 '15 at 13:00
  • @DonMax Old post, but just save the stream to disk like described here: http://stackoverflow.com/questions/5002834/saving-a-file-from-stream-to-disk-using-c-sharp – YvesR Dec 19 '16 at 10:20

1 Answers1

1

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

Dan Scally
  • 1,922
  • 1
  • 19
  • 31