【发布时间】:2019-07-10 19:06:53
【问题描述】:
有人知道如何使用 .net 的 ZipFile 类修改 zip 存档中的文本文件吗?我的意思是不解压缩所有内容,修改并再次压缩。到目前为止读取文件很容易:
using (var zip = ZipFile.Open("ExcelWorkbookWithMacros.xlsm", ZipArchiveMode.Update))
{
var entry = zip.GetEntry("xl/_rels/workbook.xml.rels");
if (entry != null)
{
var tempFile = Path.GetTempFileName();
entry.ExtractToFile(tempFile, true);
var content = File.ReadAllText(tempFile);
content = content.Replace("xxx", ""); // THIS IS WHAT I NEED TO DO
>> How to save back the archive? <<
}
}
【问题讨论】: