SQL Server
SQL Server
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
EntryByIdto retrieve the same entry later
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
SELECT @success = 0
-- Open an existing ZIP archive.
DECLARE @zip int
EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @zip, 'OpenZip', @success OUT, 'example.zip'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @zip
RETURN
END
-- Retrieve the first entry in the ZIP archive.
DECLARE @entry int
EXEC @hr = sp_OACreate 'Chilkat.ZipEntry', @entry OUT
EXEC sp_OAMethod @zip, 'EntryAt', @success OUT, 0, @entry
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @zip
EXEC @hr = sp_OADestroy @entry
RETURN
END
PRINT 'Original entry:'
EXEC sp_OAGetProperty @entry, 'FileName', @sTmp0 OUT
PRINT ' FileName: ' + @sTmp0
EXEC sp_OAGetProperty @entry, 'EntryID', @iTmp0 OUT
PRINT ' EntryID: ' + @iTmp0
PRINT ''
-- Save the EntryID for later use.
DECLARE @entryId int
EXEC sp_OAGetProperty @entry, 'EntryID', @entryId OUT
-- Create another ZipEntry object.
DECLARE @entry2 int
EXEC @hr = sp_OACreate 'Chilkat.ZipEntry', @entry2 OUT
-- Retrieve the same entry using EntryById.
EXEC sp_OAMethod @zip, 'EntryById', @success OUT, @entryId, @entry2
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @zip
EXEC @hr = sp_OADestroy @entry
EXEC @hr = sp_OADestroy @entry2
RETURN
END
PRINT 'Entry retrieved by EntryID:'
EXEC sp_OAGetProperty @entry2, 'FileName', @sTmp0 OUT
PRINT ' FileName: ' + @sTmp0
EXEC sp_OAGetProperty @entry2, 'EntryID', @iTmp0 OUT
PRINT ' EntryID: ' + @iTmp0
PRINT ''
-- The filenames and EntryID values should match.
EXEC sp_OAMethod @zip, 'CloseZip', NULL
PRINT 'Done.'
EXEC @hr = sp_OADestroy @zip
EXEC @hr = sp_OADestroy @entry
EXEC @hr = sp_OADestroy @entry2
END
GO