Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Zip Append StringBuilder

See more Zip Examples

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

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oZip
LOCAL cZipPath
LOCAL oSb
LOCAL i
LOCAL oZip2
LOCAL cZipPath2

nSuccess := 0

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

oZip := CreateObject("Chilkat.Zip")
cZipPath := "c:/temp/qa_output/out.zip"

oZip:NewZip(cZipPath)

oSb := CreateObject("Chilkat.StringBuilder")
i := 0
DO WHILE i < 100
    oSb:AppendLine("This is a test", 1)
    i := i + 1
ENDDO

oZip:AddSb("this_is_a_test.txt", oSb, "utf-8")

nSuccess := oZip:WriteZipAndClose()
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oZip:destroy()
    oSb:destroy()
    RETURN
ENDIF

? "Success 1."

//  Perhaps you want to add a file to an existing .zip
oZip2 := CreateObject("Chilkat.Zip")
//  Open the .zip we just wrote..
nSuccess := oZip2:OpenZip(cZipPath)

oSb:Clear()
i := 0
DO WHILE i < 100
    oSb:AppendLine("This is a test 2", 1)
    i := i + 1
ENDDO

oZip2:AddSb("this_is_a_test_2.txt", oSb, "utf-8")

cZipPath2 := "c:/temp/qa_output/out2.zip"
oZip2:FileName := cZipPath2
nSuccess := oZip2:WriteZipAndClose()
IF (nSuccess == 0)
    ? oZip2:LastErrorText
    oZip:destroy()
    oSb:destroy()
    oZip2:destroy()
    RETURN
ENDIF

? "Success 2."

oZip:destroy()
oSb:destroy()
oZip2:destroy()