displaying save file dialog in ASP.NET

后端 未结 1 1836
夕颜
夕颜 2021-01-21 22:45

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

相关标签:
1条回答
  • 2021-01-21 23:12

    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();
    
    0 讨论(0)
提交回复
热议问题