Xceed Zip for .NET allows you to create split zip files which have the PkZip or Xceed Zip ActiveX naming conventions through the use of the SplitNameFormat and SplitSize properties of the ZipArchive class, as well as the option to create your own custom naming convention by also handling the DiskRequired event and changing the ZipFile property of the event arguments.
To create a split zip file, the following steps must be performed:
Retrieve a reference to a folder whose files will be added to the zip file, using either the DiskFolder, ZippedFolder, ZipArchive, MemoryFolder or IsolatedFolder classes. With Xceed Zip for .NET, a folder is a folder; it does not matter if it is located within a zip file, on disk or in memory.
Retrieve a reference to a new or existing zip file using the ZipArchive class. The last part or the part that has the .zip extension must be used when creating an instance of the ZipArchive class.
Set the SplitNameFormat and SplitSize properties of the ZipArchive object to the desired values. If you want to provide your own custom naming convention, set the SplitNameFormat property to SplitNameFormat.None. In this case, you must handle the DiskRequired event.
If you want to provide your own custom naming convention, then you will need to subscribe to the DiskRequired event. You can also use the DiskRequired event to change the location where the split zip file parts are created and the size of each split part.
Call the CopyFilesTo method to copy the entire contents of the folder to the zip file.
The following example demonstrates how to create a split zip file with the PkZip naming convention.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
The next example demonstrates how to create a split zip file where each split part is located in a different folder and has the .zip extension.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
The main questions you should ask yourself when copying items to a zip file are:
Do you want to filter (specify specific files and folders) the items that are to be added to the zip file? Use filters.
Do you want to display the status of the operation? See the Events topic.
Do you want to add items into a specific folder within the zip file? Create an instance of a ZippedFolder object rather than a ZipArchive object.
Do you only want to copy a specific file or folder? Use the CopyTo method.
Do you want to move items rather than copy them? Use the MoveTo and MoveFilesTo methods.
Do you want to change the location of the temporary folder. Set the ZipArchive's TempFolder or DefaultTempFolder property.
Do you only want to do basic zip file operations? Use the QuickZip class.
Do you want to modify the default extra headers that are stored to a zip file? Set the ZipArchive's DefaultExtraHeaders property.
All zip files will automatically be created in the Zip64 zip file format if the limitations of the regular Zip format are reached.