Question

I've built a webapplication in wich a user can select a zipfile from his 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 wich 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.

Thanks in advance Ivo

Was it helpful?

Solution

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.

OTHER TIPS

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top