How to enable Web applications to export reports on the Client side
Source: Internet
Author: User
In a Web application, we cannot export a report as in a Windows application, because the program is executed on the server, and the result is also on the server when the export is executed, how can we achieve full client export? In fact, this is not difficult. The method is to export the specified report to a website and save the temporary report file, and then use response. the redirect () command directs the browser URL to the report location, so that the user's browser will try to download the exported file and the file will be downloaded to the client, to achieve the effect we need.
Some code is as follows:
Public string ExportReport ()
{
ExportOptions creo = new ExportOptions ();
DiskFileDestinationOptions crdo = new DiskFileDestinationOptions ();
String FileName = Request. PhysicalApplicationPath + "ExportFileExap.xls ";
// Set export options
Creo = Myrpt. ExportOptions;
Creo. ExportFormatType = ExportFormatType. Excel;
Creo. ExportDestinationType = ExportDestinationType. DiskFile;
// Set disk file options
Crdo. DiskFileName = FileName;
Creo. DestinationOptions = crdo;
// Export a report
MyRpt. Export ();
Return FileName;
}
Private void buttonExport_Click (object sender, System. EventArgs e)
{
String FileName = ExportReport ();
Response. Redirect (Replace (FileName, Request. PhysicalApplicationPath + "ExportFile ",""));
}
Note: When exporting files on the web, you must have the permission to create files for the export directory. If you do not have the permission, "access to report files is denied..." appears ......" .
Let the ASPNET user (the system user automatically generated when the. NET Framework is installed) have the "write" permission on the exported directory stationery.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.