PowerTCP Zip Compression for .NET
BeginQuickZip(String,Stream,Object) Method
Example 




The names or wildcards of the files to be compressed.
A Stream that is to contain the compressed data.
User state information. Use this to pass data to your EndXXX event handler.
Asynchronously add files and create a zip archive.
Syntax
<DescriptionAttribute("Begins an asynchronous Zip operation, zip a given source to a stream.")>
Public Overloads Function BeginQuickZip( _
   ByVal source As String, _
   ByVal destination As Stream, _
   ByVal state As Object _
) As IAsyncResult
Dim instance As Archive
Dim source As String
Dim destination As Stream
Dim state As Object
Dim value As IAsyncResult
 
value = instance.BeginQuickZip(source, destination, state)
[Description("Begins an asynchronous Zip operation, zip a given source to a stream.")]
public IAsyncResult BeginQuickZip( 
   string source,
   Stream destination,
   object state
)
[Description("Begins an asynchronous Zip operation, zip a given source to a stream.")]
public: IAsyncResult* BeginQuickZip( 
   string* source,
   Stream* destination,
   Object* state
) 
[Description("Begins an asynchronous Zip operation, zip a given source to a stream.")]
public:
IAsyncResult^ BeginQuickZip( 
   String^ source,
   Stream^ destination,
   Object^ state
) 

Parameters

source
The names or wildcards of the files to be compressed.
destination
A Stream that is to contain the compressed data.
state
User state information. Use this to pass data to your EndXXX event handler.

Return Value

An IAsyncResult that represents the asynchronous operation, which could still be pending.
Exceptions
ExceptionDescription
System.InvalidOperationExceptionBeginXXX method used without providing an EndXXX event handler.
ZipExceptionA critical zip operation error occurred during this activity. Please see ZipException.Message for details.
Remarks

This method is a quick and easy way to use the Archive component to compress a given file or files to the specified destination Stream. It combines the two operations of Archive.Add and Archive.Zip.

The Archive.Password and Archive.Encryption properties are used for data encryption during the BeginQuickZip operation. The Archive.PreservePath property determines whether to preserve paths for each file item. The Archive.IncludeSubs property determines whether to include the subdirectories. The Archive.ExcludePattern property determines the files to exclude.

Note that data is written to the Stream at the current position and will not be reset to 0.

If an error occurs for an individual item during this operation, the Archive.Exception Event will be raised.

Example
The following example demonstrates using BeginQuickZip for an asynchronous zip operation. Only BeginQuickZip is required in this operation.
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Zip"
' at the top of your class.

' Preserve the path structure of the files
Archive1.PreservePath = True

' Include any subdirectories
Archive1.IncludeSubs = True

' Exclude any text files
Archive1.ExcludePattern = "*.txt"

' Set to use encryption
Archive1.DefaultEncryption = Encryption.Standard

' Specify the password
Archive1.Password = "testme"

' Perform the asynchronous compression operation
Archive1.BeginQuickZip("c:\Test\*.txt", "c:\test.zip", Nothing)

Private Sub Archive1_EndZip(ByVal sender As Object, ByVal e As Dart.PowerTCP.Zip.EndEventArgs) Handles Archive1.EndZip
    Try
        If e.Exception Is Nothing Then
            MessageBox.Show("Zip Complete!")
        Else
            MessageBox.Show(e.Exception.Message)
        End If

    Catch

    End Try
End Sub
// Be sure to import the namespace by putting "using Dart.PowerTCP.Zip;"
// at the top of your class.

// Preserve the path structure of the files
archive1.PreservePath = true;

// Include any subdirectories
archive1.IncludeSubs = true;

// Exclude any text files
archive1.ExcludePattern = "*.txt";

// Set to use encryption
archive1.DefaultEncryption = Encryption.Standard;
// Specify the password

archive1.Password = "testme";

// Perform the asynchronous compression operation
archive1.BeginQuickZip("c:\\Test\\*.txt", "c:\\test.zip", null);

private void archive1_EndZip(object sender, Dart.PowerTCP.Zip.EndEventArgs e)
{
	try
	{
		if (e.Exception == null)
			MessageBox.Show("Zip Complete!");
		else
			MessageBox.Show(e.Exception.Message);
	}
	catch {}

}
See Also

Reference

Archive Class
Archive Members
Overload List


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