Sample code for 30+ languages & platforms
VB.NET

Zip Append StringBuilder

See more Zip Examples

Append the contents of a Chilkat StringBuilder object to a .zip.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim zip As New Chilkat.Zip
Dim zipPath As String = "c:/temp/qa_output/out.zip"

zip.NewZip(zipPath)

Dim sb As New Chilkat.StringBuilder
Dim i As Integer = 0
While i < 100
    sb.AppendLine("This is a test",True)
    i = i + 1
End While

zip.AddSb("this_is_a_test.txt",sb,"utf-8")

success = zip.WriteZipAndClose()
If (success = False) Then
    Debug.WriteLine(zip.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("Success 1.")

' Perhaps you want to add a file to an existing .zip
Dim zip2 As New Chilkat.Zip
' Open the .zip we just wrote..
success = zip2.OpenZip(zipPath)

sb.Clear()
i = 0
While i < 100
    sb.AppendLine("This is a test 2",True)
    i = i + 1
End While

zip2.AddSb("this_is_a_test_2.txt",sb,"utf-8")

Dim zipPath2 As String = "c:/temp/qa_output/out2.zip"
zip2.FileName = zipPath2
success = zip2.WriteZipAndClose()
If (success = False) Then
    Debug.WriteLine(zip2.LastErrorText)
    Exit Sub
End If


Debug.WriteLine("Success 2.")