我已经编写了一个方法,如下所示,将多个内存流绑定到ziparchive。该代码适用于一个流,但如果我通过迭代添加多个流,则会在for循环的第2行中显示以下错误。
System.IO.IOException: 'Entries cannot be created
while previously created entries are still open.' 我的密码
using (var zip = new ZipArchive(outputStream, ZipArchiveMode.Create,
leaveOpen: false))
{
for (int i = 0; i < msList.Count; i++)
{
msList[i].Position = 0;
var createenter = zip.CreateEntry("123"+i+".jpg",
CompressionLevel.Optimal);
msList[i].CopyTo(createenter.Open());
}
}发布于 2018-08-07 05:23:19
您可能错过了打开的using Stream
using (var zip = new ZipArchive(outputStream, ZipArchiveMode.Create, leaveOpen: false))
{
for (int i = 0; i < msList.Count; i++)
{
msList[i].Position = 0;
var createenter = zip.CreateEntry("123"+i+".jpg",
CompressionLevel.Optimal);
using (var s = createenter.Open())
{
msList[i].CopyTo(s);
}
}
}https://stackoverflow.com/questions/51719292
复制相似问题