Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Create WinZip Compatible Password-Protected ZipVisual Basic sample code to create a WinZip compatible password-protected Zip. Dim ZipFile As ChilkatZip2 Private Sub Command1_Click() ' Get the zip file name CommonDialog1.ShowOpen CommonDialog1.CancelError = True SourceFile.Text = CommonDialog1.FileName End Sub Private Sub Command2_Click() ' Create a ChilkatZip object Set ZipFile = New ChilkatZip2 ZipFile.UnlockComponent UnlockCode.Text ZipFile.NewZip OutputZip.Text ' To create a WinZip-compatible password-protected Zip, simply ' set the PasswordProtect property to 1, and set a password. ' To unzip, WinZip will prompt for this password. ZipFile.PasswordProtect = 1 ZipFile.SetPassword "secret" ' Add the disk file to the Zip object ZipFile.AppendFiles SourceFile.Text, 0 ' See if anything was added. If (ZipFile.NumEntries = 0) Then ZipStatus.Caption = "Error, no files added to the Zip archive." Set ZipFile = Nothing Exit Sub End If ' Compress and write to disk. success = ZipFile.WriteZip() If (success = 0) Then MsgBox ZipFile.LastErrorText Exit Sub End If ' How much compression occured? Dim e As ChilkatZipEntry2 Set e = ZipFile.GetEntryByIndex(0) If (Not (e Is Nothing)) Then origSize = e.UncompressedLength compressedSize = e.CompressedLength ZipStatus.Caption = "Success." + vbCrLf + Str(origSize) + " bytes compressed to " + Str(compressedSize) + " bytes" Set e = Nothing End If ZipFile.CloseZip Set ZipFile = Nothing End Sub Private Sub Form_Load() OutputZip.Text = CurDir$ + "\outputFile.zip" End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.