简体   繁体   中英

displaying save file dialog in ASP.NET

I'm going to display a save file dialog in my asp.net web page, user clicks a button and a save file dialog appears which allows user to save a report in CSV format in his hard disk, how can I do it? is it possible to display save file dialog in ASP.NET? thanks

To do this, you'll want to create a whole new page (or, better, *.ashx handler) to serve up the CSV results. The button should post a GET request to this page. When it receives the request, in either the ProcessRequest() method (for a handler) or the Page_Load() method (for a Page), you will have code like this:

Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader( "Content-Disposition", "attachment;filename=\"report.csv\"" );
// write your CSV data to Response.OutputStream here
Response.End();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM