我正在开发一个项目,我更新 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 保存到流中?
您可以使用 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));
}
}