This is a method that will compress a directory of files using the ShellClass and the Shell32 api.
Public Sub startCompression(ByVal stateInfo As Object)
Dim strArgs As String = ""
Dim strdest As String = ""
'----- Check the file for a .zip extenstion.
strdest += strDestinationFile
If System.IO.Path.GetExtension(strdest).ToUpper.EndsWith(".ZIP") = False Then
strdest += ".zip"
End If
If strdest.IndexOf(" ") <> -1 Then
strdest = """" & strdest & """"
End If
'----- Binary Array representing a zip file header.
Dim emptyZip As Byte() = New Byte() {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
'----- Write out the zip file
Dim fs As FileStream = File.Create(Me.strDestinationFile)
fs.Write(emptyZip, 0, emptyZip.Length)
fs.Flush()
fs.Close()
fs = Nothing
Dim sc As ShellClass = New ShellClass
Dim src As Shell32.Folder = sc.NameSpace(Me.strSourceDir)
Dim dst As Shell32.Folder = sc.NameSpace(Me.strDestinationFile)
'----- Begining File Compression in System Controlled Thread
dst.CopyHere(src, 20)
'----- Sleep to allow the compression thread to begin execution
System.Threading.Thread.CurrentThread.Sleep(5000) ' 5 seconds is usually more than enough
End Sub