Invalid zip file after creating it with System.IO.Compression

后端 未结 4 1693
死守一世寂寞
死守一世寂寞 2021-02-12 15:58

I\'m trying to create a zip file that contains one or more files.
I\'m using the .NET framework 4.5 and more specifically System.IO.Compression namespace.
The objectiv

4条回答
  •  [愿得一人]
    2021-02-12 16:04

    Try changing

    using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create, false))
    

    to

    using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
    

    In this usage, the archive is forced to write to the stream when it is closed. However, if the leaveOpen argument of the constructor is set to false, it will close the underlying stream too.

提交回复
热议问题