PowerTCP Zip Compression for .NET
QuickUnzip



The QuickUnzip method presents a quick and easy way to decompress a given zip archive to a source directory on disk. It combines the two operations of Open and Unzip. The source can be a filename or compressed stream. The destination is a path on disk.

Quickly unzipping from a compressed file

To quickly and easily unzip a file archive to a path on disk:

  1. Add the Archive component to a new form.
  2. Add a button to the form.
  3. Specify the archive properties. For example, set the Password and Encryption properties to decrypt the entire collection. In the example to follow, all files in the zip archive "c:\test.zip" are extracted to the directory "c:\Test". The archived files' paths are preserved during decompression, and all existing files will be overwritten.
  4. Use the QuickUnzip method to extract files from the zip archive.
  5. Compile and run the application. After pressing the button, the archived files contained in "c:\test.zip" will be extracted to the path "c:\Test".
C#
Copy Code
archive1.PreservePath = true;
archive1.Overwrite = Overwrite.Always;
Archive1.QuickUnzip("c:\test.zip", "c:\Test");

Visual Basic
Copy Code
Archive1.PreservePath = True
Archive1.Overwrite = Always
Archive1.QuickUnzip("c:\test.zip", "c:\Test")

Quickly unzipping from a compressed stream

To unzip a compressed stream to a path on disk:

  1. Follow steps 1, 2 and 3 above, for unzipping from a compressed file.
  2. Use the QuickUnzip method to extract the items in a compressed stream to a path on disk. The stream could be a FileStream (see the example below), or a MemoryStream (see the compressing to a stream section of the Using QuickZip section).
  3. Compile and run the application. After pressing the button, the files from the compressed archive should be found in "c:\Test".
C#
Copy Code
System.IO.FileStream stream = new System.IO.FileStream("c:\\test.zip", System.IO.FileMode.Open);
archive1.QuickUnzip(stream, "c:\\Test");
Visual Basic
Copy Code
Dim stream As New System.IO.FileStream("c:\test.zip", System.IO.FileMode.Open)
Archive1.QuickUnzip(stream, "c:\Test")

Asynchronous quick unzipping

To unzip a file archive asynchronously:

  1. Follow steps 1, 2 and 3 above, for unzipping from a compressed file.
  2. Use the asynchronous BeginQuickUnzip method to extract the archived files.
  3. Add code for the EndUnzip Event. When using the BeginXXX methods, you must have corresponding EndXXX events (see Asynchronous Operation for more details).
  4. Compile and run the application. After pressing the button, the archived files contained in "c:\test.zip" will be extracted to the path "c:\Test".
C#
Copy Code
archive1.BeginQuickUnzip("c:\\test.zip", "c:\\Test", null);
...
private void archive1_EndUnzip(object sender, Dart.PowerTCP.Zip.EndEventArgs e)
{
    try
    {
        if (e.Exception == null)
            MessageBox.Show("Extraction Complete!");
    else
        MessageBox.Show(e.Exception.Message);
    }
    catch {}
}
Visual Basic
Copy Code
Archive1.BeginQuickUnzip("c:\test.zip", "c:\Test", Nothing) 
... 
Private Sub Archive1_EndUnzip(ByVal sender As Object, ByVal e As Dart.PowerTCP.Zip.EndEventArgs) Handles Archive1.EndUnzip Archive1.EndZip
    Try
        If (e.Exception Is Nothing) Then
            MessageBox.Show("Extraction Complete!")
        Else
            MessageBox.Show(e.Exception.Message)
        End If
    Catch
    End Try
End Sub 

PowerTCP Zip for .NET Documentation Version 2.1.1
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic