从StreamWriter输出.txt文件而不写入磁盘?

nas*_*ski 1 .net c# asp.net

有没有办法获取StreamWriter并将文件(在本例中为.txt文件)输出给用户,并选择打开/保存而不实际将文件写入磁盘?如果没有保存它将基本消失.

我正在寻找相同的功能

HttpContext.Current.Response.TransmitFile(file);
Run Code Online (Sandbox Code Playgroud)

但无需将任何内容保存到磁盘.谢谢!

Spe*_*nce 8

试试吧 System.IO.MemoryStream

System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.StreamWriter sw = new System.IO.StreamWriter(ms);
sw.Write("hello");
Run Code Online (Sandbox Code Playgroud)