写入文件"关于即时"用C#客户端

编程入门 行业动态 更新时间:2024-10-24 07:26:59
本文介绍了写入文件"关于即时"用C#客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用C#和ASP.NET 2.5。

I'm using C# and ASP.NET 2.5.

我想要一个简单的方法来生成即时文件(让我们说这个例子CSV文件),并将其传送给客户端,而实际上它写入服务器文件系统。

I want a simple way to generate a "file" on-the-fly (let's say a csv file for this example) and transmit it to the client without actually writing it to the server file system.

推荐答案

一些搜索和反复试验后,我制定了以下。这似乎正好符合要求。它应该是很容易适应PHP或任何其他服务器端软件,因为它主要涉及到修改的标题。

After some searching and trial and error, I developed the following. It seems to fit the bill exactly. It should be very easily adaptable to PHP or any other server-side software since it mostly involves modifying headers.

protected void streamToResponse() { Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=testfile.csv"); Response.AddHeader("content-type", "text/csv"); using(StreamWriter writer = new StreamWriter(Response.OutputStream)) { writer.WriteLine("col1,col2,col3"); writer.WriteLine("1,2,3"); } Response.End(); }

更多推荐

写入文件"关于即时"用C#客户端

本文发布于:2023-05-25 10:56:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   文件   QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!