C# | Visual Basic | Visual C++ |
public void Save()
Public Sub Save
public: void Save()
The ZipFile instance is written to storage, typically a zip file in a filesystem, only when the caller calls Save. In the typical case, 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.
The Name property is specified either explicitly, or implicitly using one of the parameterized ZipFile constructors. For COM Automation clients, the Name property must be set explicitly, because COM Automation clients cannot call parameterized constructors.
When using a filesystem file for the Zip output, it is possible to call Save multiple times on the ZipFile instance. With each call the zip content is re-written to the same output file.
Data for entries that have been added to the ZipFile instance is written to the output when the Save method is called. This means that the input streams for those entries must be available at the time the application calls Save. If, for example, the application adds entries with AddEntry using a dynamically-allocated MemoryStream, the memory stream must not have been disposed before the call to Save. See the InputStream property for more discussion of the availability requirements of the input stream for an entry, and an approach for providing just-in-time stream lifecycle management.
Exception | Condition |
---|---|
BadStateException |
Thrown if you haven't specified a location or stream for saving the zip,
either in the constructor or by setting the Name property, or if you try
to save a regular zip archive to a filename with a .exe extension.
|
OverflowException |
Thrown if MaxOutputSegmentSize is non-zero, and the number
of segments that would be generated for the spanned zip file during the
save operation exceeds 99. If this happens, you need to increase the
segment size.
|