Save the file to a new zipfile, with the given name.
![](collapse_all.gif)
![](collapse_all.gif)
- fileName (String)
- The name of the zip archive to save to. Existing files will be overwritten with great prejudice.
![](collapse_all.gif)
This method allows the application to explicitly specify the name of the zip file when saving. Use this when creating a new zip file, or when updating a zip archive.
An application can also save a zip archive in several places by calling this method multiple times in succession, with different filenames.
The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. The Save operation writes the zip content to a temporary file, and then renames the temporary file to the desired name. If necessary, this method will delete a pre-existing file before the rename.
![](collapse_all.gif)
This example shows how to create and Save a zip file.
CopyC#
CopyVB.NET
![](CopyCode.gif)
using (ZipFile zip = new ZipFile()) { zip.AddDirectory(@"c:\reports\January"); zip.Save("January.zip"); }
![](CopyCode.gif)
Using zip As New ZipFile() zip.AddDirectory("c:\reports\January") zip.Save("January.zip") End Using
![](collapse_all.gif)
This example shows how to update a zip file.
CopyC#
CopyVB.NET
![](CopyCode.gif)
using (ZipFile zip = ZipFile.Read("ExistingArchive.zip")) { zip.AddFile("NewData.csv"); zip.Save("UpdatedArchive.zip"); }
![](CopyCode.gif)
Using zip As ZipFile = ZipFile.Read("ExistingArchive.zip") zip.AddFile("NewData.csv") zip.Save("UpdatedArchive.zip") End Using
![](collapse_all.gif)
Exception | Condition |
---|---|
ArgumentException |
Thrown if you specify a directory for the filename.
|