Reputation: 2087
I have a Stimulsoft report in my ASP.Net web application.
I want to export it using this C# code.
report.ExportDocument(StiExportFormat.Excel2007, "d:\\ExportedFile.xlsx", exportSettings);
but this code exports the report to server, not the client.
How can I save the report to client's storage?
Upvotes: 0
Views: 3658
Reputation: 146
You can use ExportDocument() method on the report
MemoryStream st = new MemoryStream();
report.ExportDocument(StiExportFormat.Excel2007, st);
Upvotes: 2
Reputation: 1329
You should use StiReportResponse class. It returns the report exported to specified format.
StiReportResponse.ResponseAsPdf(this, report);
StiReportResponse.ResponseAsExcel2007(this, report);
You cold get more information in the Stimulsoft Programming Manual.
Upvotes: 1
Reputation: 2087
I found the answer by myself.
I should write the exported data to a MemoryStream, not a file. then send the MemoryStream to the Response of Current HttpContext. In this way a download dialog will be open and ask about donwload path on Client storage.
MemoryStream memoryStream = new MemoryStream();
renderedReport.ExportDocument(StiExportFormat.Excel2007, memoryStream, exportSettings);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Emad.xlsx");
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
HttpContext.Current.Response.End();
Upvotes: 0