将 ZipArchive 保存到 Stream

问题描述 投票:0回答:1

我正在开发一个项目,我更新 ZipArchive 并将其上传回服务器,但我只能使用流上传它。

public IActionResult DeleteZippedFile(string path)
{
    //read the zip from stream
    var zip = new ZipArchive(DownloadStream(Request.Cookies["OpenedZipPath"]), ZipArchiveMode.Update);

    //make changes
    zip.Entries.Where(x => x.Name == path).ToList()[0].Delete();

    //i want to convert here <------
    ftp.UploadStream(THESTREAMIWANT)

    //and back to the zip
    return RedirectToAction(nameof(OpenZip));
}

如何将 ZipArchive 保存到流中?

c# .net zip memorystream c#-ziparchive
1个回答
0
投票

您可以使用 ZipArchive.Save 方法保存 ziparchiece

public IActionResult DeleteZippedFile(string path)
{
    var zip = new ZipArchive(DownloadStream(Request.Cookies["OpenedZipPath"]), ZipArchiveMode.Update); 

    zip.Entries.Where(x => x.Name == path).ToList()[0].Delete();
    using (MemoryStream updatedZipStream = new MemoryStream())
    {
        zip.Save(updatedZipStream); 

        updatedZipStream.Seek(0, SeekOrigin.Begin); 

        ftp.UploadStream(updatedZipStream); 

        RedirectToAction(nameof(OpenZip));
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.