VB.NET to Extract a File from one Zip Archive and Append it to Another Zip Archive

The following VB.NET code copies the contents of the nutrition.xml file (found in xml1.zip) to another pre-existing .zip named xml2.zip:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim zip1 As New Chilkat.Zip
        Dim success As Boolean

        success = zip1.UnlockComponent("Anything for 30-day trial")

        success = zip1.OpenZip("xml1.zip")

        Dim entry As Chilkat.ZipEntry
        entry = zip1.GetEntryByName("nutrition.xml")
        ' Assume the entry was found and is non-null

        ' Now we'll add this entry to a different already-existing zip archive.
        ' To avoid re-writing the entire zip, we use QuickAppend.
        ' In this example, the already-existing .zip is "xml2.zip"

        ' Create a new zip object for the purpose of holding the entries that will
        ' be appended to xml2.zip
        Dim zipTemp As New Chilkat.Zip

        ' Retrieve the compressed data from the entry object and add it to our
        ' temporary zip object.
        zipTemp.AppendCompressed("nutrition.xml", entry.Copy())

        ' Append all the entries in zipTemp to the existing zip file named "xml2.zip"
        ' This writes the entries in zipTemp (all in memory) to xml2.zip
        success = zipTemp.QuickAppend("xml2.zip")

    End Sub

Tags :