[英]How to download a file created in the server's memory to the client without saving it?
How to download a file created in the server's memory to the client without saving it (ASP.NET)? 如何在不保存的情况下将在服务器内存中创建的文件下载到客户端(ASP.NET)?
I've generated an Excel file on server using NetOffice. 我已经使用NetOffice在服务器上生成了一个Excel文件。 BUT now, I am not able to download it to the client.
但是现在,我无法将其下载到客户端。 I don't want to save a copy of this file on the server.
我不想将此文件的副本保存在服务器上。
Can we send the file object created in the memory using Streams? 我们可以使用Streams发送在内存中创建的文件对象吗?
Indeed you can. 确实可以。 Just pass to Response.OutputStream of your HTTP request.
只需传递到HTTP请求的Response.OutputStream。 Something like this should work (where yourStream is a stream from your in memory excel doc):
这样的事情应该可以工作(其中yourStream是您的内存excel文档中的流):
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment; filename=myfile.xlsx");
yourStream.WriteTo(Response.OutputStream);
Response.Flush();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.