• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

XceedZip load contents of zip file into byte array VB.NET

I am trying to load a file out of a zip file into a byte array. This seems to be working correctly, however it only ever seems to populate the array with the compressed version of the file, not the entire file.

Im guessing that this is because it is not being unzipped? However I can not for the life of me work out how to do this?

Here is the code that I am currently using...

        Dim DF As New DiskFile(SomeFileName)
        Dim zip As New ZipArchive(DF)
        Dim folder As New MemoryFolder("RAM_DISK", "folder")
        zip.CopyFilesTo(folder, True, True)

        Dim files() As AbstractFile = zip.GetFiles(True, "*.*")
        Dim file As AbstractFile

        Dim S1 As Stream
        Dim oReceivedFile as byte()

        For Each file in files  
                        S1 = file.OpenRead
                        oReceivedPDFFile = New Byte(S1.Length) {}
                        S1.Read(oReceivedFile, 0, S1.Length)

oReceivedFile only ever seems to have the unzipped file in it...

any help would be fantastic.

1 Solution
The docs for XceedZip are not very enlightening, but I notice that you unzip the archive into a MemoryFolder but call GetFiles on the original archive (zip.GetFiles(True, "*.*")).  Try calling GetFiles in the MemoryFolder instead (folder.GetFiles(True, "*.*")).
MTSDLAuthor Commented:
Thanks alot dricahrds... that worked a treat :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now