The exceptions that can be thrown by UltimateZip are handled in the same manner as regular runtime exception using Try/Catch blocks.
The following table provides a list of the custom exceptions that can be thrown when an error occurs:
Exception | Description |
---|---|
ZipException | Exception that is thrown when an error occurs while processing Zip file. |
FileSystemException | Exception that is thrown when an error occurs while adding or extracting files and directories. |
Example below shows how to handle these exceptions:
using ComponentPro.Compression; using System; ... try { // 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"); // Close the zip file. zip.Close(); } catch (ZipException exc) { Console.WriteLine("Error: " + exc.Message); }