PowerTCP Zip Compression for .NET

from $299.00
Available Platforms

See all PowerTCP Zip Compression for .NET Code Examples

Compress Folder Code Example

The following C# example demonstrates compression of a folder using the Archive component. The archive is AES 256 encrypted. Progress is provided during the operation.


private void buttonZip_Click(object sender, EventArgs e)
        //Encrypt the zip file using AES 256.
        archive1.DefaultEncryption = Dart.PowerTCP.Zip.Encryption.Aes256Bit;
        archive1.Password = "321!thisIsMyPassword";

        //Add a folder to the zip file.
        //Include subfolders, preserve paths, and do not include txt files.
        archive1.IncludeSubs = true;
        archive1.PreservePath = true;
        archive1.ExcludePattern = "*.txt";

        //Create the zip file.
    catch (Exception ex)
        //Display message if operation encounters an error.
        textWarnings.AppendText("Error: " + ex.Message + Environment.NewLine);

private void archive1_Progress(object sender, Dart.PowerTCP.Zip.ProgressEventArgs e)
    //Show zip progress for each item in the folder.
    progressItem.Maximum = 100;
    double itemPercent = ((double)e.ProcessedItemBytes / (double)e.Item.Size) * 100;
    progressItem.Value = Convert.ToInt16(itemPercent);

    //Show zip progress for the entire folder.
    progressTotal.Maximum = 100;
    double totalPercent = ((double)e.ProcessedTotalBytes / (double)e.TotalBytes) * 100;
    progressTotal.Value = Convert.ToInt16(totalPercent);

private void archive1_Exception(object sender, Dart.PowerTCP.Zip.ExceptionEventArgs e)
    //Display any warnings that occur during the operation.
    textWarnings.AppendText("Warning: " + archive1[e.Index].Name + " - " +
        e.Exception.Message + Environment.NewLine);


 The PowerTCP Zip Compression for .NET Compress a Folder example is included with a trial installation of PowerTCP Zip Compression for .NET. To download a trial please visit the PowerTCP Zip Compression for .NET product page.