This project is read-only.

[VB] I need help reading into a zip file and extracting files

Sep 19, 2013 at 5:02 PM
Edited Sep 19, 2013 at 5:16 PM
What I need to do is read into a zip file and copy out just a certain file that is specified by the user and put it in a destination folder. I've looked at a lot of different examples and have come up with different sets of code that don't work. If anyone could offer any help or advice, it would be greatly appreciated, thank you! Here are some examples:


Using zip As Ionic.Zip.ZipFile = ZipFile.Read(fileName.FullName)
                Dim entries As Ionic.Zip.ZipFile = zip.SelectEntries(stidToFind & ".crt")

                zip.ExtractSelectedEntries(stidToFind & ".crt", String.Empty, destinationDirectory, ExtractExistingFileAction.OverwriteSilently)

                End Using


                    Using zip As ZipFile = ZipFile.Read(fileName.FullName)
                        Dim zipToExtract As ZipEntry
                       For Each zipToExtract In zip
                           zipToExtract.Extract(stidToFind & "*.crt")
                    End Using
                Catch ex1 As Exception
                   Console.Error.WriteLine("exception: {0}", ex1.ToString)

End Try


Using zip As ZipFile = ZipFile.Read(fileName.FullName)
                    Dim Threshold As Integer = stidToFind
                    ' We cannot remove the entry from the list, within the context of
                    ' an enumeration of said list.
                    ' So we add the doomed entry to a list to be removed later.
                    ' pass 1: mark the entries for removal
                    Dim MarkedEntries As New System.Collections.Generic.List(Of ZipEntry)
                    Dim entry As ZipEntry
                    For Each entry In zip
                        If (entry.Equals(Threshold)) Then
                        End If
                    ' pass 2: actually remove the entry.
                    Dim selectedZip As ZipEntry
                    For Each selectedZip In MarkedEntries
                        zip.ExtractSelectedEntries(selectedZip, String.Empty, destinationDirectory)

                End Using

                Dim zip As Ionic.Zip.ZipFile = ZipFile.Read(fileName.FullName)
                For Each ZipEntry In zip
                    If ZipEntry.Info.Contains(stidToFindInt & ".crt") Then

                        MsgBox("File Found : " & ZipEntry.FileName)

                        'Extract File
                        ZipEntry.Extract(FileIO.FileSystem.CurrentDirectory, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
                        (ZipEntry, destinationDirectory)
                        MsgBox("File : " & ZipEntry.FileName & " Extracted")

                    End If