0

I've built a webapplication in which a user can select a zipfile from their filesystem (via an asp:FileUpload). Then the application unzips the zipfile and ftp's every file.

here's the code:

Public Sub Unzip(ByVal str As Stream, ByVal constr As String)
    Dim zf As New ZipFile(str)
    Dim ze As ZipEntry
    Dim i As Integer = 0
    While i < zf.Count
        ze = zf.EntryByIndex(i)
        i = i + 1
        Dim ftp As New ftpItem(constr)
        ftp.upload(ze.Name, "pic", zf.GetInputStream(i), ze.Name, ze.Name)

    End While
    zf.Close() 
End Sub

The ftpItem class is a class of my own which handles the ftp. ftp.upload needs as third parameter the stream for the file to be sent.

But for some reason zf.GetInputStream(i) always gives nothing.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Ivo
  • 5
  • 3

2 Answers2

0

I think you are at the end of the stream, try moving to the begining of the stream so you can read everything.

str.Seek(0, SeekOrigin.Begin)
Chris Kooken
  • 32,730
  • 15
  • 85
  • 123
0

For one thing, you should increment i inside the loop AFTER you call GetInputStream. If there is only one file this logic will always fail, I imagine.

While i < zf.Count
    ze = zf.EntryByIndex(i)

    Dim ftp As New ftpItem(constr)
    ftp.upload(ze.Name, "pic", zf.GetInputStream(i), ze.Name, ze.Name)

    i = i + 1

End While

If that does not work, there is a purportedly working C# example here, using a different method GetNextEntry to iterate the list of compressed files.

Community
  • 1
  • 1
Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
  • Moving to the begining does not help. still the same result. the increment was indeed in the wrong place. But even placing it right does not help. The entries I get are good, if I run the debugger and I ask ze.Name, it gives me the names of the files; just like ze.Size gives me the right size for the files. (I've also tried iterating like the c# example with no luck) – Ivo Nov 02 '10 at 18:59
  • @user495089 - is that comment for me, or the answer below? Seems to me like you have a simple logic error here – Steve Townsend Nov 02 '10 at 19:02
  • Have you tried just writing the uncompressed data to a local file (`FileStream`) or `MemoryStream` instead of using FTP? What do properties look like on `zf.GetInputStream()`? What it the interface to `upload`? Just a `Stream`, or some other class as param 3? – Steve Townsend Nov 02 '10 at 19:20
  • @Ivo - great, glad to hear it – Steve Townsend Nov 03 '10 at 19:41