Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save ZipArchive to file

In my application I have a class manipulating with zip archive using System.IO.Compression.ZipArchive. Now I want to save the entries of the archive to file. How can I do that? I know I can associate a Stream with archive but in my case the archive creates w/o streams and I can't change the code:

var archive = ZipFile.Open(fileName, ZipArchiveMode.Create);
// add entries
// how can I save it to file now?
like image 584
folibis Avatar asked Feb 27 '17 14:02

folibis


1 Answers

You are already 'saving it to a file', the one indicated by fileName.

To make sure everything is written and flushed, use a using :

using (var archive = ZipFile.Open(fileName, ZipArchiveMode.Create))
{
   // add entries
   ....

}  // here it is saved and closed
like image 193
Henk Holterman Avatar answered Oct 16 '22 12:10

Henk Holterman