How to add files and folders to an archive

This topic demonstrates how to add files and folders to an archive using Ultimate Zip component. To add files and folders to an archive, you need to perform the following steps:

  1. Specify a folder path whose files will be added to the archive.
  2. Retrieve a reference to a new or existing archive file using the Zip class.
  3. Call AddFile or AddFiles methods to copy or move existing files to the archive.

See the following example more more details:

C#

// Create a new instance.
 Zip zip = new Zip();
 // Create a new zip file.
 zip.Create("test.zip");
 // Set password
 zip.EncryptionAlgorithm = EncryptionAlgorithm.PkzipClassic;
 zip.Password = "password";
 // Add all files and subdirectories from 'c:\test' to the archive.
 zip.AddFiles(@"c:\test");
 // Add all files and subdirectories from 'c:\my folder' to the archive.
 zip.AddFiles(@"c:\my folder", "");
 // Add all files and subdirectories from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles(@"c:\my folder2", "22");
 // Add all .dat files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles(@"c:\my folder2", "22", "*.dat");
 // Or simply use this to add all .dat files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles(@"c:\my folder2\*.dat", "22");
 // Add *.dat and *.exe files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles(@"c:\my folder2\*.dat;*.exe", "22");
 // Close the zip file.
 zip.Close();

VB.NET

' Create a new instance.
 Dim zip As New Zip()
 ' Create a new zip file.
 zip.Create("test.zip")
 ' Set password
 zip.EncryptionAlgorithm = EncryptionAlgorithm.PkzipClassic
 zip.Password = "password"
 ' Add all files and subdirectories from 'c:\test' to the archive.
 zip.AddFiles("c:\test")
 ' Add all files and subdirectories from 'c:\my folder' to the archive.
 zip.AddFiles("c:\my folder", "")
 ' Add all files and subdirectories from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles("c:\my folder2", "22")
 ' Add all .dat files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles("c:\my folder2", "22", "*.dat")
 ' Or simply use this to add all .dat files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles("c:\my folder2\*.dat", "22")
 ' Add *.dat and *.exe files from 'c:\my folder' to '22' folder within the archive.
 zip.AddFiles("c:\my folder2\*.dat;*.exe", "22")
 ' Close the zip file.
 zip.Close()