SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

How to unzip 1st file from Zip in Memory and save it?

Last post 05-09-2008 6:33 AM by DavidPierson. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-16-2008 12:48 PM

    How to unzip 1st file from Zip in Memory and save it?

     I have written code that doesnt throw any errors but it somehow srews up the file so i cant open it. Anyway if someone has done this before and have code please share it with me.

     

    This is what i got so far maybe someone knows whats wrong with it:

     Public Sub UnzipFirstFileSharpZipLibInMemory(ByVal BytesOfArchive() As Byte, ByVal PathOfFile As String)

                Dim msZipInputStream As New MemoryStream(BytesOfArchive) ';'

                Dim s As ZipInputStream = New ZipInputStream(msZipInputStream)
                Dim theEntry As ZipEntry

                Dim blnFirstFileInArchive As Boolean = True

                While True

                    theEntry = s.GetNextEntry
                    If theEntry Is Nothing Or blnFirstFileInArchive = False Then
                        Exit While
                    Else
                        blnFirstFileInArchive = False
                    End If

                   Dim fileName As String = Path.GetFileName(theEntry.Name)
               
                  If Not fileName = String.Empty Then
                        Dim streamWriter As New MemoryStream
                        Dim size As Integer = 2048
                        Dim data(2048) As Byte

                        While True
                            size = s.Read(data, 0, data.Length)
                            If size > 0 Then
                                streamWriter.Write(data, 0, size)
                            Else
                                Exit While
                            End If
                        End While
                      

                        Dim bytFile(streamWriter.Length - 1) As Byte
                        streamWriter.Read(bytFile, 0, streamWriter.Length)
                        My.Computer.FileSystem.WriteAllBytes(PathOfFile, bytFile, False)
                        streamWriter.Close()
                    End If

                End While
                s.Close()

  • 03-16-2008 2:18 PM In reply to

    Re: How to unzip 1st file from Zip in Memory and save it?

    Dim s As ZipInputStream = New ZipInputStream(msZipInputStream)

    Dim theEntry As ZipEntry

    Their is an error in this words.

    Is Their a Reference must be added to work the underline words above.

  • 03-17-2008 11:08 AM In reply to

    Re: How to unzip 1st file from Zip in Memory and save it?

     Yeah you need to add ICSharpCode.SharpZipLib.dll as a reference to yor project.

    It can be downloaded .... http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx. Here.

     

  • 05-09-2008 6:33 AM In reply to

    Re: How to unzip 1st file from Zip in Memory and save it?

    I believe you need to reset the position of the streamwriter before reading back from it.

    Just before this line near the end of your method ...

       streamWriter.Read(bytFile, 0, streamWriter.Length)

     add the following

    streamWriter.Position = 0; 

     

     

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.