• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 713 Replies
    2021 Replies
  • 331 Replies
    1928 Replies
The site is still being updated (as of 14th Jan 2018 6PM GMT) but can be used in the meantime.

Reading file from zip file without extracting

Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
User avatar
AnoPem
VIP - Donator
Posts: 441

Reading file from zip file without extracting

Thu Nov 10, 2016 10:26 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 ?
Image

User avatar
CodenStuff
Site Admin
Posts: 4348

Re: Reading file from zip file without extracting

Sun Nov 13, 2016 6:11 pm

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
Posts: 441

Re: Reading file from zip file without extracting

Sun Nov 13, 2016 6:21 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 ?
Image

User avatar
CodenStuff
Site Admin
Posts: 4348

Re: Reading file from zip file without extracting

Sun Nov 13, 2016 8:31 pm

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.

Post Reply

Return to “Coding Help & Support”