gpt4 book ai didi

c# - DotNetZip 从 MemoryStream 打开 zip 文件

转载 作者:行者123 更新时间:2023-11-30 21:01:43 26 4
gpt4 key购买 nike

我喜欢做的不是在磁盘上存储 zip 文件,而是喜欢从 MemoryStream 打开它。

我正在查看 DotNetZip 编程示例的文档:请注意,我根据我认为可能需要的内容对其进行了微调。

    var ms = new MemoryStream();
using (ZipFile zip = new ZipFile())
{
zip.AddFile("ReadMe.txt");
zip.AddFile("7440-N49th.png");
zip.AddFile("2008_Annual_Report.pdf");
zip.Save(ms); // this will save the files in memory steam
}


// now what I need is for the zip file to open up so that
the user can view all the files in it. Not sure what to do next after
zip.Save(ms) for this to happen.

最佳答案

试试这个:

public ActionResult Index()
{
var memoryStream = new MemoryStream();

using (var zip = new ZipFile())
{
zip.AddFile("ReadMe.txt");
zip.AddFile("7440-N49th.png");
zip.AddFile("2008_Annual_Report.pdf");
zip.Save(memoryStream);
}

memoryStream.Seek(0, 0);
return File(memoryStream, "application/octet-stream", "archive.zip");
}

关于c# - DotNetZip 从 MemoryStream 打开 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com