Xceed Real-Time Zip for .NET Documentation
Unzip(String,String,String,Boolean,Boolean,Boolean,DiskRequiredCallback,Object,String[]) Method
Example 


Xceed.Zip Assembly > Xceed.Zip Namespace > QuickZip Class > Unzip Method : Unzip(String,String,String,Boolean,Boolean,Boolean,DiskRequiredCallback,Object,String[]) Method
The fully-qualified path and name of the zip file.
The destination folder to where the files will be extracted.
The password that will be used to decrypt the files.
Boolean value indicating if existing files should be overwritten.
Boolean value indicating if files contained within sub-folders should be extracted from the zip file.
Boolean value indicating if the directory structure should be preserved in the destination folder.
The callback method called whenever the DiskRequired event is triggered.
Opaque data which will be passed back to the callback method.
The files to extract from zipFileName. Cannot be a null reference (Nothing in Visual Basic).
Extracts files from a spanned zip file specifying the callback method called when requesting a new disk, providing a decryption password and specifying whether existing files will be overwritten and if the directory structure will be restored.
Syntax
'Declaration
 
Public Overloads Shared Sub Unzip( _

   ByVal zipFileName As String, _

   ByVal destinationFolder As String, _

   ByVal decryptionPassword As String, _

   ByVal replaceExistingFiles As Boolean, _

   ByVal recursive As Boolean, _

   ByVal preservePaths As Boolean, _

   ByVal diskRequiredCallback As QuickZip.DiskRequiredCallback, _

   ByVal userParams As Object, _

   ByVal ParamArray filesToUnzip() As String _

) 
'Usage
 
Dim zipFileName As String

Dim destinationFolder As String

Dim decryptionPassword As String

Dim replaceExistingFiles As Boolean

Dim recursive As Boolean

Dim preservePaths As Boolean

Dim diskRequiredCallback As QuickZip.DiskRequiredCallback

Dim userParams As Object

Dim filesToUnzip() As String

 

QuickZip.Unzip(zipFileName, destinationFolder, decryptionPassword, replaceExistingFiles, recursive, preservePaths, diskRequiredCallback, userParams, filesToUnzip)

Parameters

zipFileName
The fully-qualified path and name of the zip file.
destinationFolder
The destination folder to where the files will be extracted.
decryptionPassword
The password that will be used to decrypt the files.
replaceExistingFiles
Boolean value indicating if existing files should be overwritten.
recursive
Boolean value indicating if files contained within sub-folders should be extracted from the zip file.
preservePaths
Boolean value indicating if the directory structure should be preserved in the destination folder.
diskRequiredCallback
The callback method called whenever the DiskRequired event is triggered.
userParams
Opaque data which will be passed back to the callback method.
filesToUnzip
The files to extract from zipFileName. Cannot be a null reference (Nothing in Visual Basic).
Remarks

Zip files are case sensitive therefore the string passed in the filesToUnzip parameter, will be used "as-is".

For example, if a zip file contains a file named "FILE.TXT" and "file.txt" is passed to the filesToUnzip parameter, "FILE.TXT" will not be extracted.

If the destination item(s) exists, the attributes and dates of the original item(s) are not applied to the destination item(s).

Handling paths

When extracting files from within a zip file, the directory structure can be restored fully or partially or it can be omitted altogether.

If the preservePaths parameter of the Unzip method is set to false, the files specified in the filesToUnzip parameter will be restored directly into the root of the destination folder without recreating the directory structure.

For example, if you have a zip file containing files in the "folder1" subfolder and files in the "folder1\folder2" subfolder, the following code will unzip all files right into "c:\temp", without creating any subfolders:

C# Copy Code
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, false, @"folder1\*" );

If the preservePaths parameter is set to true, the part of the path that is explicitly included in the filesToUnzip parameter will not be restored into the destination folder.

For example, for the same zip file as above, the following code will create the folder "folder2" into the "c:\temp" destination folder. Files that were in the "folder1" subfolder in the zip will be unzipped directly into the root of "c:\temp", and files that were in "folder1\folder2" will be unzipped into "c:\temp\folder2":

C# Copy Code
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, true, @"folder1\*" );

The following example will unzip files into "c:\temp\folder1" and "c:\temp\folder1\folder2":

C# Copy Code
Xceed.Zip.QuickZip.Unzip( @"c:\test.zip", @"c:\temp", true, true, true, @"*" );
Example
The following example demonstrates how to extract the contents of a spanned zip file.
QuickZip.Unzip( "a:\test.zip", "d:\", string.Empty, true, true, false, _

                New QuickZip.DiskRequiredCallback(AddressOf Me.QuickDiskRequired), _

                Nothing, "*" ) 



' This method will handle the DiskRequired events that are raised when creating 

' spanned or split zip files. 



Private Function QuickDiskRequired(ByVal zipFile As String, ByVal diskNumber As Integer, _

                                   ByVal userData As Object) As Boolean 

  If (MessageBox.Show("Disk #" + diskNumber.ToString() + _

                      " is required.", "Disk Required", _

                      MessageBoxButtons.OKCancel) = DialogResult.OK) Then 

    Return True Else Return False 

  End If 

End Function
QuickZip.Unzip( @"a:\test.zip", @"d:\", string.Empty, true, true, 

                false, new QuickZip.DiskRequiredCallback( this.QuickDiskRequired ),

                null, "*" ); 



// This method will handle the DiskRequired events that are raised when creating 

// spanned or split zip files. 

private bool QuickDiskRequired( string zipFile, int diskNumber, object userData ) 

{ 

  if( MessageBox.Show( "Disk #" + diskNumber.ToString() + " is required.", 

                       "Disk Required", MessageBoxButtons.OKCancel ) == DialogResult.OK ) 

    return true; else return false; 

}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

QuickZip Class
QuickZip Members
Overload List