Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Open Zip from URL (OpenFromWeb)Open a .zip from a URL and unzip. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @zip int EXEC @hr = sp_OACreate 'Chilkat.Zip2', @zip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Any string unlocks the component for the 1st 30-days. EXEC sp_OAMethod @zip, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Downloads a .zip into memory and opens it. EXEC sp_OAMethod @zip, 'OpenFromWeb', @success OUT, 'http://www.chilkatsoft.com/testData/hamlet.zip' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- It can be unzipped to disk: DECLARE @fileCount int EXEC sp_OAMethod @zip, 'Unzip', @fileCount OUT, 'c:/temp' IF @fileCount < 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Alternatively, individual entries may be unzipped into memory. -- In this case, it is unzipped into a string: DECLARE @fileContents nvarchar(4000) DECLARE @entry int DECLARE @addCR int SELECT @addCR = 1 EXEC sp_OAMethod @zip, 'GetEntryByName', @entry OUT, 'hamlet.xml' IF Not (@entry Is NULL ) BEGIN -- If the file has bare LF line endings, add the CR to get -- CRLF line endings. EXEC sp_OAMethod @entry, 'InflateToString', @fileContents OUT, @addCR PRINT @fileContents END END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.