Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • 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 :-)

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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