Thanks to http://stackoverflow.com/a/12350106/222748 I got:

using (var memoryStream = new MemoryStream())
{
   using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
   {
      var demoFile = archive.CreateEntry("foo.txt");

      using (var entryStream = demoFile.Open())
      using (var streamWriter = new StreamWriter(entryStream))
      {
         streamWriter.Write("Bar!");
      }
   }

   using (var fileStream = new FileStream(@"C:\Temp\test.zip", FileMode.Create))
   {
      memoryStream.Seek(0, SeekOrigin.Begin);
      memoryStream.CopyTo(fileStream);
   }
}

So we need to call dispose on ZipArchive before we can use it, which means passing 'true' as the third parameter to the ZipArchive so we can still access the stream after disposing it.

相关文章:

  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-10-31
  • 2021-12-21
  • 2021-04-09
猜你喜欢
  • 2021-07-21
  • 2021-06-14
  • 2022-12-23
  • 2021-11-10
  • 2021-06-28
  • 2021-07-22
  • 2022-12-23
相关资源
相似解决方案