Page 1 of 1

Reading file from zip file without extracting

Posted: Thu Nov 10, 2016 9:26 pm
by AnoPem
Hello im trying to read images from a zip file, but i dont want to extract the zip i just want to stream the data to an array or something, does anyone know if this is possible with DotNetZip ?

Re: Reading file from zip file without extracting

Posted: Sun Nov 13, 2016 5:11 pm
by CodenStuff
I think you can do this in VB

First add references to:
System.IO.Compression
System.IO.Compression.FileSystem


Then using this code:
Code: Select all
Dim zipPath As String = "C:\TestFile.zip"
        Dim UnzippedStream As Stream
        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                If entry.FullName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) Then
                    UnzippedStream = entry.Open
                    Using reader = New StreamReader(UnzippedStream)
                        RichTextBox1.Text = reader.ReadToEnd()
                    End Using
                End If
            Next
        End Using
You can read the contents of the zip file and do whatever you need to do without extracting it.

In the example I'm opening a zip file that contains a html file and displaying the contents of that file in a richtextbox.

Hope this helps you get started :)

Re: Reading file from zip file without extracting

Posted: Sun Nov 13, 2016 5:21 pm
by AnoPem
CodenStuff wrote:
I think you can do this in VB

First add references to:
System.IO.Compression
System.IO.Compression.FileSystem


Then using this code:
Code: Select all
Dim zipPath As String = "C:\TestFile.zip"
        Dim UnzippedStream As Stream
        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                If entry.FullName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) Then
                    UnzippedStream = entry.Open
                    Using reader = New StreamReader(UnzippedStream)
                        RichTextBox1.Text = reader.ReadToEnd()
                    End Using
                End If
            Next
        End Using
You can read the contents of the zip file and do whatever you need to do without extracting it.

In the example I'm opening a zip file that contains a html file and displaying the contents of that file in a richtextbox.

Hope this helps you get started :)

What .NET version is this and what should i import ?

Re: Reading file from zip file without extracting

Posted: Sun Nov 13, 2016 7:31 pm
by CodenStuff
Any from .NET 4.0 upwards

If you go to project > add reference you can add the ones I mentioned from the list.