Reading file from zip file without extracting

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

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 ?
https://t.me/pump_upp
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

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 :)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

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 ?
https://t.me/pump_upp
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Any from .NET 4.0 upwards

If you go to project > add reference you can add the ones I mentioned from the list.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
4 posts Page 1 of 1
Return to “Coding Help & Support”