The QuickZip method presents a quick and easy way to compress a given source to a specified zip archive. It combines the two operations of Add and Zip into a single operation. The source is a filename, and can include wildcards. The destination can be a file or stream, according to the application needs.
To quickly and easily zip a file or wildcard collection of files to a compressed file:
C# |
Copy Code |
---|---|
archive1.PreservePath = true; archive1.IncludeSubs = true; archive1.ExcludePattern = "*.txt"; archive1.QuickZip("c:\\Test\\*.*", "c:\\test.zip"); |
Visual Basic |
Copy Code |
---|---|
Archive1.PreservePath = True Archive1.IncludeSubs = True Archive1.ExcludePattern = "*.txt" Archive1.QuickZip("c:\Test\*.*", "c:\test.zip") |
To zip a file or wildcard collection of files to a compressed stream:
C# |
Copy Code |
---|---|
System.IO.MemoryStream stream = new System.IO.MemoryStream(); archive1.QuickZip("c:\\Test\\*.*", stream); MessageBox.Show("The size of the compressed stream is " + stream.Length.ToString() + " bytes."); |
Visual Basic |
Copy Code |
---|---|
Archive1.QuickZip("c:\Test\*.*", stream) Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream() MessageBox.Show("The size of the compressed stream is " + stream.Length.ToString() + "bytes.") |
To zip a file or wildcard collection of files asynchronously:
C# |
Copy Code |
---|---|
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 {} } |
Visual Basic |
Copy Code |
---|---|
Archive1.BeginQuickZip("c:\Test\*.*", "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 |