|
-
Dec 24th, 2009, 01:23 AM
#1
Thread Starter
Member
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.
-
Dec 24th, 2009, 01:32 AM
#2
Addicted Member
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
-
Dec 24th, 2009, 01:43 AM
#3
Thread Starter
Member
Re: unzipping a file
VS.net 2008 doesn't like the Java parts and there is nothing i can import that works.
-
Dec 24th, 2009, 01:43 AM
#4
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.
-
Dec 24th, 2009, 01:59 AM
#5
Thread Starter
Member
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.
-
Dec 24th, 2009, 02:10 AM
#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.
-
Dec 24th, 2009, 06:47 AM
#7
Re: unzipping a file
 Originally Posted by Wargod18
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|