ASP.NET从内存而不是从文件中流内容
发布时间:2020-12-16 00:01:27 所属栏目:asp.Net 来源:网络整理
导读:用户已请求“下载”GridView内容的csv文件表示的选项.有没有人知道如何在不将文件保存到服务器的情况下执行此操作,而只是将其从内存中流式传输给用户? 谢谢 解决方法 实现IHttpHandler. 我在ProcessResponse中使用类似于以下的东西来输出之前在数据库表中构
用户已请求“下载”GridView内容的csv文件表示的选项.有没有人知道如何在不将文件保存到服务器的情况下执行此操作,而只是将其从内存中流式传输给用户?
谢谢 解决方法
实现IHttpHandler.
我在ProcessResponse中使用类似于以下的东西来输出之前在数据库表中构造的CSV … public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; HttpRequest request = context.Request; //Get data to output here... //Turn off Caching and enforce a content type that will prompt to download/save. response.AddHeader("Connection","close"); response.AddHeader("Cache-Control","private"); response.ContentType = "application/octect-stream"; //Give the browser a hint at the name of the file. response.AddHeader("content-disposition",string.Format("attachment; filename={0}",_filename)); //Output the CSV here... foreach(BatchDTO.BatchRecordsRow row in dtoBatch.BatchRecords) response.Output.WriteLine(row.Data); response.Flush(); response.Close(); } 有许多库可以使生成CSV变得更容易,您应该只能将它传递给Response.OutputStream以使其写入那里而不是文件流. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 如何在Mvccontrib网格模型中使用自定义列
- asp.net – 如何添加一个空的第一个条目做一个?
- asp.net-mvc – Server 2008 R2上的MVC – 如何?
- asp.net – 移动浏览器设备检测在.NET
- asp.net – 您如何看待Postgres和Firebird数据库?
- asp.net-mvc – thinktecture identityserver v3
- asp.net – 没有Eval的GridGroupHeaderItem.AggregatesValu
- ASP.net C#:如何使用File.ReadLines(fileName).GetEnumera
- asp.net-web-api – 使用Web API的Autofac:从HttpRequestM
- asp.net – IdentitySever3重定向多个域的URL
推荐文章
站长推荐
热点阅读