从内存ASP.NET流的内容,而不是从文件

问题描述:

在用户请求下载的内容GridView的csv文件重新presentation的选项。有谁知道如何做到这一点,而不将文件保存到服务器上,而是只需将它从内存流给用户?

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 but rather just streaming it to the user from memory?

感谢

我创建一个StringBuilder并使用以下code(CSV是StringBuilder的变量)转储内容Response对象。

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();