Create a Zip-File into a Zip-File

Sep 14, 2009 at 7:21 PM
Edited Sep 15, 2009 at 2:41 PM

Dear all,

how can I create Zip-Files into one new Zip-File?

For example the following steps:
-create a Zip-File named result.zip
-create a Zip-File named test1.zip with all files and folders from path C:\results\test1\*.* (with path) and store this into result.zip
-create a Zip-File named test2.zip with all files and folders from path D:\result\all users\test2\*.* and store this also into result.zip

When is it possible, I would use a memorystream to create all zip-files.

I had seen this example (I think so), but I cannot find it again.

Thanks for your support.

regards,
Maximilian

Coordinator
Sep 14, 2009 at 8:26 PM
    Public Sub Run()
        Using s1 As Stream = ZipIntoMemory("c:\temp\dir1")
            Using s2 As Stream = ZipIntoMemory("c:\temp\dir2")
                Using zip1 as New ZipFile 
                    zip1.AddEntry("test1.zip", "", s1)
                    zip1.AddEntry("test2.zip", "", s2)
                    zip1.Save("Tescher.zip") ' can also save to a Stream here
                End Using
            End Using
        End Using
    End Sub

    Public Function ZipIntoMemory(ByVal path As String) As Stream
        Dim ms As New MemoryStream
        Using zip1 as New ZipFile 
            zip1.AddDirectory(path, "Result")
            zip1.Save(ms)
        End Using
        ' move the stream position to the beginning
        ms.Seek(0,SeekOrigin.Begin)
        Return ms
    End Function