ASP.NET stream content from memory and not from file

前端 未结 4 524
失恋的感觉
失恋的感觉 2020-12-18 16:15

The users have requested the option to \"download\" a csv file representation of GridView contents. Does anyone know how to do this without saving the file to the server bu

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 16:39

    I created a StringBuilder and dump the contents to the Response object using the following code ("csv" is the StringBuilder variable).

        Response.ContentType = @"application/x-msdownload";
        Response.AppendHeader("content-disposition", "attachment; filename=" + FILE_NAME);
    
        Response.Write(csv.ToString());
        Response.Flush();
        Response.End();
    

提交回复
热议问题