Sample code for 30+ languages & platforms
Lianja

Zip Append StringBuilder

See more Zip Examples

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

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loZip = createobject("CkZip")
lcZipPath = "c:/temp/qa_output/out.zip"

loZip.NewZip(lcZipPath)

loSb = createobject("CkStringBuilder")
i = 0
do while i < 100
    loSb.AppendLine("This is a test",.T.)
    i = i + 1
enddo

loZip.AddSb("this_is_a_test.txt",loSb,"utf-8")

llSuccess = loZip.WriteZipAndClose()
if (llSuccess = .F.) then
    ? loZip.LastErrorText
    release loZip
    release loSb
    return
endif

? "Success 1."

// Perhaps you want to add a file to an existing .zip
loZip2 = createobject("CkZip")
// Open the .zip we just wrote..
llSuccess = loZip2.OpenZip(lcZipPath)

loSb.Clear()
i = 0
do while i < 100
    loSb.AppendLine("This is a test 2",.T.)
    i = i + 1
enddo

loZip2.AddSb("this_is_a_test_2.txt",loSb,"utf-8")

lcZipPath2 = "c:/temp/qa_output/out2.zip"
loZip2.FileName = lcZipPath2
llSuccess = loZip2.WriteZipAndClose()
if (llSuccess = .F.) then
    ? loZip2.LastErrorText
    release loZip
    release loSb
    release loZip2
    return
endif

? "Success 2."


release loZip
release loSb
release loZip2