Results 1 to 7 of 7

Thread: unzipping a file

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    48

    unzipping a file

    I want to unzip a file but from what i found out the .net framework cant do this and I have to use 3rd party software which I'm fine with I downloaded sharpziblib but I can't figure out how to install it and how it could be used on computers that don't have it installed.

  2. #2
    Addicted Member
    Join Date
    Jul 2009
    Posts
    140

    Re: unzipping a file

    use this code to unzip the file
    Code:
     If Uncompress(zipfile, rootdir) = True Then
            msgbox("ZIP File Extracted Successfully")
                      
                End If
    Code:
      Public Function Uncompress(ByVal strZipFileName As String, ByVal strLocation As String) As Boolean
            Try
    
                Dim dir, newpath As String
                Dim oFileInputStream As New java.io.FileInputStream(strZipFileName)
                Dim oZipInputStream As New java.util.zip.ZipInputStream(oFileInputStream)
                Dim bTrue As Boolean = True
                Dim sbBuf(1024) As SByte
    
                While 1 = 1
                    Dim oZipEntry As ZipEntry = oZipInputStream.getNextEntry()
    
                    If oZipEntry Is Nothing Then Exit While
    
                    If oZipEntry.isDirectory Then
                        If Not My.Computer.FileSystem.DirectoryExists(strLocation & oZipEntry.getName) Then
                            My.Computer.FileSystem.CreateDirectory(strLocation & oZipEntry.getName)
                        End If
                    Else
    
                        dir = System.IO.Path.GetDirectoryName(oZipEntry.getName())
                        newpath = strLocation & "\" & dir
    
                        If Directory.Exists(newpath) = False Then
                            System.IO.Directory.CreateDirectory(newpath)
                        End If
    
                        Dim oFileOutputStream As New java.io.FileOutputStream(strLocation.Replace("\", "/") & oZipEntry.getName())
    
                        While 1 = 1
                            Dim iLen As Integer = oZipInputStream.read(sbBuf)
                            If iLen < 0 Then Exit While
                            oFileOutputStream.write(sbBuf, 0, iLen)
                        End While
                        oFileOutputStream.close()
                    End If
                End While
                oZipInputStream.close()
                oFileInputStream.close()
    
                Return True
    
            Catch ex As Exception
    
          
                Throw New Exception(ex.Message)
    
                Return False
            End Try
    
        End Function

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    48

    Re: unzipping a file

    VS.net 2008 doesn't like the Java parts and there is nothing i can import that works.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: unzipping a file

    #ZipLib is just an assembly, i.e. .NET DLL, so you simply reference it from your project. If you follow the CodeBank link in my signature you can check out my code example. It was written for .NET 1.x but the code should still be valid.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    48

    Re: unzipping a file

    i see you imported it but i tried that and it doesn't work. what folder does it go in so I can import it. even your code example doesn't like it.

  6. #6

    Re: unzipping a file

    I found a zip handling DLL that does handle zip files nicely by Ionic located here called the DotNetZip Library. It's quite simple to use and works really well.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: unzipping a file

    Quote Originally Posted by Wargod18 View Post
    i see you imported it but i tried that and it doesn't work. what folder does it go in so I can import it. even your code example doesn't like it.
    I didn't import anything and it doesn't have to go in any folder. As I said, you reference the DLL. Go to the References page of the project properties and add a reference. You can then navigate to the DLL wherever it is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width