Imports System.IO Namespace Framework Public Class Zip Public cDestinationFile As String = "" Public cSourceFolder As String = "" Public cError As String = "" Public cFile As String = "" Private oFile As Collection = New Collection() Private oApp As Framework.App Private oProcess As Framework.LXProcess ' This is when we access the data provider in desktop and Web service mode Public Sub New(ByVal toApplication As Framework.App) oApp = toApplication End Sub ' This is when we access the data provider in desktop and Web service mode Public Sub New(ByVal toProcess As Framework.LXProcess) oProcess = toProcess oApp = oProcess.oApp End Sub ' Zip a file Public Function Zip() As Boolean Dim lcFile As String = "" Dim llOK As Boolean = False Dim loByte(21) As Byte Dim loObject As Object Dim loDestinationFolder As Shell32.Folder Dim loFile As Shell32.FolderItem Dim loShellClass As Shell32.ShellClass = New Shell32.ShellClass Dim loSourceFolder As Shell32.Folder Try ' If the source folder does not exist If Not oApp.DirectoryExist(cSourceFolder) Then cError = "The directory " + cSourceFolder + " does not exist." Exit Try End If loSourceFolder = loShellClass.NameSpace(cSourceFolder) loByte(0) = 80 : loByte(1) = 75 : loByte(2) = 5 : loByte(3) = 6 ' Make an empty PKZip file File.WriteAllBytes(cDestinationFile, loByte) loDestinationFolder = loShellClass.NameSpace(cDestinationFile) ' For each file For Each loObject In oFile lcFile = loObject(1) ' If the file does not exist If Not oApp.FileExist(cSourceFolder + "\" + lcFile) Then cError = "The file " + cSourceFolder + "\" + lcFile + " does not exist." ' Remove the temporary file If Not oApp.DeleteFile(cDestinationFile) Then End If Exit Try End If loFile = loSourceFolder.Items.Item(lcFile) loDestinationFolder.CopyHere(loFile, 20) Next llOK = True Catch loError As Exception cError = loError.Message End Try Return llOK End Function ' Add a file ' expC1 File name Public Function AddFile(ByVal tcFile As String) As Boolean Dim loObject(1) As Object loObject(1) = tcFile oFile.Add(loObject) Return True End Function End Class End NamespaceTo initiate:
Dim loZip As Framework.Framework.Zip = New Framework.Framework.Zip(oApp) loZip.cSourceFolder = "d:\" loZip.AddFile("Server.docx") loZip.AddFile("Test.jpg") loZip.cDestinationFile = "d:\Test\Test.zip" If Not loZip.Zip() Then MessageBox.Show("Error: " + loZip.cError) Exit Sub End IfIt makes use of the Shell to accomplish. This is a very fast and fully compliant with the shell extension as installed with WinZip.