Sample code for 30+ languages & platforms
Visual FoxPro

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loBd
LOCAL loZip
LOCAL loEntry
LOCAL lnLineEndingBehavior
LOCAL lcXmlStr
LOCAL loSb

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

loBd = CreateObject('Chilkat.BinData')

* This URL is valid and can be tested...
lnSuccess = loHttp.QuickGetBd("https://chilkatdownload.com/example_data/hamlet.zip",loBd)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loBd
    CANCEL
ENDIF

loZip = CreateObject('Chilkat.Zip')

* Open the zip from the bytes contained in bd.
lnSuccess = loZip.OpenBd(loBd)
IF (lnSuccess = 0) THEN
    ? loZip.LastErrorText
    RELEASE loHttp
    RELEASE loBd
    RELEASE loZip
    CANCEL
ENDIF

* Get the entry for the file we want..
loEntry = CreateObject('Chilkat.ZipEntry')
lnSuccess = loZip.EntryOf("hamlet.xml",loEntry)
IF (lnSuccess = 0) THEN
    ? loZip.LastErrorText
    RELEASE loHttp
    RELEASE loBd
    RELEASE loZip
    RELEASE loEntry
    CANCEL
ENDIF

* Convert all line endings to CRLF (if needed)
lnLineEndingBehavior = 2
lcXmlStr = loEntry.UnzipToString(lnLineEndingBehavior,"utf-8")
IF (loEntry.LastMethodSuccess = 0) THEN
    ? loEntry.LastErrorText
    RELEASE loHttp
    RELEASE loBd
    RELEASE loZip
    RELEASE loEntry
    CANCEL
ENDIF

* The XML in this case is about 274K, so let's just examine the last 20 lines...
loSb = CreateObject('Chilkat.StringBuilder')
loSb.Append(lcXmlStr)

? loSb.LastNLines(20,1)

RELEASE loHttp
RELEASE loBd
RELEASE loZip
RELEASE loEntry
RELEASE loSb