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




A filename that will contain the compressed data.
User state information. Use this to pass data to your EndXXX event handler.
Asynchronously compress the items in the current collection and generate a zip archive that is written to a file.
Syntax
<DescriptionAttribute("Begins an asynchronous Zip operation, zip to a file.")>
Public Overloads Function BeginZip( _
   ByVal destination As String, _
   ByVal state As Object _
) As IAsyncResult
Dim instance As Archive
Dim destination As String
Dim state As Object
Dim value As IAsyncResult
 
value = instance.BeginZip(destination, state)
[Description("Begins an asynchronous Zip operation, zip to a file.")]
public IAsyncResult BeginZip( 
   string destination,
   object state
)
[Description("Begins an asynchronous Zip operation, zip to a file.")]
public: IAsyncResult* BeginZip( 
   string* destination,
   Object* state
) 
[Description("Begins an asynchronous Zip operation, zip to a file.")]
public:
IAsyncResult^ BeginZip( 
   String^ destination,
   Object^ state
) 

Parameters

destination
A filename that will 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
ZipExceptionA critical zip operation error occurred during this activity. Please see ZipException.Message for details.
Remarks

The Archive.Password and Archive.Encryption properties are used for data encryption during the BeginZip 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.

During a zip operation, the source files are never altered in any manner unless the destination file has the same name as the source file. In that case, the file loaded with Open will be updated to contain the results of the zip operation. To prevent any unanticipated damage, the zip operation updates the destination only after a zip operation completes successfully.

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

Example
The following example demonstrates adding files to the collection and asynchronously zipping them.
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Zip"
' at the top of your class.

' Add a file using the ArchiveItem constructor
Dim item = New ArchiveItem("c:\Test\file1.txt")

' Add a comment to this item
item.Comment = "This is file1.txt"

' Use encryption for just this item
item.Encryption = Encryption.Standard
item.Password = "testme"

Archive1.Add(item)

' Add a file using the filename.  This could also be used for adding wildcard collections
Archive1.Add("c:\Test\file2.log")

' Add a wildcard collection of files
' In this case, all "txt" files in the directory "c:\Test" are added, except "file1.txt"
' Subfolders are not included, but the paths are preserved.
Archive1.IncludeSubs = True
Archive1.ExcludePattern = "file1.txt"
Archive1.PreservePath = True
Archive1.Add("c:\Test\*.txt")

' Start the zipping processes
Archive1.BeginZip("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.

// Add a file using the ArchiveItem constructor
ArchiveItem item = new ArchiveItem("c:\\Test\\file1.txt");

// Add a comment to this item
item.Comment = "This is file1.txt";

// Use encryption for just this item
item.Encryption = Encryption.Standard;
item.Password = "testme";

archive1.Add(item);

// Add a file using the filename.  This could also be used for adding wildcard collections
archive1.Add("c:\\Test\\file2.log");

// Add a wildcard collection of files
// In this case, all "txt" files in the directory "c:\Test" are added, except "file1.txt"
// Subfolders are not included, but the paths are preserved.
archive1.IncludeSubs = true;
archive1.ExcludePattern= "file1.txt";
archive1.PreservePath = true;
archive1.Add("c:\\Test\\*.txt");

// Start the zipping processes
archive1.BeginZip("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