简体   繁体   English

如何在不保存的情况下将在服务器内存中创建的文件下载到客户端?

[英]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.

相关问题 如何使用内存使用C#打开创建的WorkBook而不保存? - How to open created WorkBook with C# using memory, without saving it? 创建excel文件并下载而不将其保存到服务器中,可以吗? - Create excel file and download it without saving it into the server, is it possible? 创建要下载的文件而无需使用C#保存在服务器上 - Create file for download without saving on server with C# 保存对话框下载文件,将文件从 ASP.NET 服务器保存到客户端 - Save dialog box to download file, Saving file from ASP.NET server to the client 通过AJAX MVC下载Excel文件,而无需将文件保存在ASP.Net/C#中的服务器上 - Download Excel file via AJAX MVC without saving the file on server in ASP.Net/C# 从FileResult下载文件而不保存到磁盘 - Download File from FileResult without saving to disk 在 ASP.net Core MVC 2.1 中创建文本文件并下载而不保存在服务器上 - Create text file and download without saving on server in ASP.net Core MVC 2.1 如何在不保存ms访问文件的情况下将ms访问文件的数据从Web应用程序获取到ms sql服务器 - How to take ms access file's datas from web application to ms sql server without saving ms access file 通过我的服务器将文件从远程服务器复制到客户端浏览器,而无需将整个文件写入磁盘或内存 - Copy file from remote server to client browser via my server without writing the entire file to disk or memory 在 memory 中创建 eml 文件而不将其保存在磁盘上 - Create eml file in memory without saving it on disk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM