Save ZipArchive to Stream

I am working on a project where i update a ZipArchive and upload it back to server but I can only upload it using a stream.

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));
}

How can i save ZipArchive to a stream?

  • You can save ziparchiece using by ZipArchive.Save method

    – 

  • You created the ZipArchive using a Stream in the first place, so that is the Stream you should be using. If you need to reference that object again later then obviously you need to assign it to a variable. If you can’t use that particular Stream for whatever reason then copy the data from it to another Stream first and then create the ZipArchive from that.

    – 

Leave a Comment