Sample code for 30+ languages & platforms
Unicode C

Find a ZIP Entry by EntryID Using EntryById

See more Zip Examples

This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.

Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.

This is useful when:

  • An application stores EntryID values for later use
  • ZIP entries need to be retrieved without searching by filename
  • Multiple entries may have similar names or paths

The example:

  • Opens a ZIP archive
  • Retrieves an entry using EntryAt
  • Saves the entry's EntryID
  • Uses EntryById to retrieve the same entry later

Chilkat Unicode C Downloads

Unicode C
#include <C_CkZipW.h>
#include <C_CkZipEntryW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkZipW zip;
    HCkZipEntryW entry;
    int entryId;
    HCkZipEntryW entry2;

    success = FALSE;

    success = FALSE;

    // Open an existing ZIP archive.
    zip = CkZipW_Create();

    success = CkZipW_OpenZip(zip,L"example.zip");
    if (success == FALSE) {
        wprintf(L"%s\n",CkZipW_lastErrorText(zip));
        CkZipW_Dispose(zip);
        return;
    }

    // Retrieve the first entry in the ZIP archive.
    entry = CkZipEntryW_Create();

    success = CkZipW_EntryAt(zip,0,entry);
    if (success == FALSE) {
        wprintf(L"%s\n",CkZipW_lastErrorText(zip));
        CkZipW_Dispose(zip);
        CkZipEntryW_Dispose(entry);
        return;
    }

    wprintf(L"Original entry:\n");
    wprintf(L"  FileName: %s\n",CkZipEntryW_fileName(entry));
    wprintf(L"  EntryID: %d\n",CkZipEntryW_getEntryID(entry));
    wprintf(L"\n");

    // Save the EntryID for later use.
    entryId = CkZipEntryW_getEntryID(entry);

    // Create another ZipEntry object.
    entry2 = CkZipEntryW_Create();

    // Retrieve the same entry using EntryById.
    success = CkZipW_EntryById(zip,entryId,entry2);
    if (success == FALSE) {
        wprintf(L"%s\n",CkZipW_lastErrorText(zip));
        CkZipW_Dispose(zip);
        CkZipEntryW_Dispose(entry);
        CkZipEntryW_Dispose(entry2);
        return;
    }

    wprintf(L"Entry retrieved by EntryID:\n");
    wprintf(L"  FileName: %s\n",CkZipEntryW_fileName(entry2));
    wprintf(L"  EntryID: %d\n",CkZipEntryW_getEntryID(entry2));
    wprintf(L"\n");

    // The filenames and EntryID values should match.
    CkZipW_CloseZip(zip);

    wprintf(L"Done.\n");


    CkZipW_Dispose(zip);
    CkZipEntryW_Dispose(entry);
    CkZipEntryW_Dispose(entry2);

    }