C# | Visual Basic | Visual C++ |
public ZipFile()
Public Sub New
public: ZipFile()
See the documentation on the ZipFile constructor that accepts a single string argument for basic information on all the ZipFile constructors.
After instantiating with this constructor and adding entries to the archive, the application should call Save(String) or Save(Stream) to save to a file or a stream, respectively. The application can also set the Name property and then call the no-argument Save()()()() method. (This is the preferred approach for applications that use the library through COM interop.) If you call the no-argument Save()()()() method without having set the Name of the ZipFile, either through the parameterized constructor or through the explicit property , the Save() will throw, because there is no place to save the file.
Instances of the ZipFile class are not multi-thread safe. You may have multiple threads that each use a distinct ZipFile instance, or you can synchronize multi-thread access to a single instance.
using (ZipFile zip = new ZipFile()) { // Store all files found in the top level directory, into the zip archive. // note: this code does not recurse subdirectories! String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip); zip.AddFiles(filenames, "files"); zip.Save("Backup.zip"); }
Using zip As New ZipFile ' Store all files found in the top level directory, into the zip archive. ' note: this code does not recurse subdirectories! Dim filenames As String() = System.IO.Directory.GetFiles(DirectoryToZip) zip.AddFiles(filenames, "files") zip.Save("Backup.zip") End Using