dragank

dragank

  • NA
  • 7
  • 0

How to extract zip file programmatically

May 26 2005 4:03 AM
Hai all, I am doing a project in vb.net. i need to extract zip file programmatically[which will be in some other location]. i have written a method, but it is failing. basically the inout to the methods are (1) zip file name (along with the full path of its location Eg: c:\myfolder\testing\test.zip), (2) the destination path. so the code has to extract in the same hierarchial folder structure. i'm using vjslib.dll, which embedds the java functionality (including zip). Can any one plse help me in solving this. Would be greatful - I have pasted my code below. with regards, karthik ************************************************************* Imports java.util.zip Imports java.io Imports java.util Private Sub btnExtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExtract.Click Dim SrcFilePath As String = txtFilePath.Text Dim DestFilePath As String = txtDestpath.Text Dim SrcBuffer As BufferedInputStream Dim DestBuffer As BufferedOutputStream Dim LZipEntry As ZipEntry Dim LFile As File Dim TempFile As File Dim tempfilestr As String Dim LZipfile As New ZipFile(SrcFilePath) Dim LEnum As Enumeration = LZipfile.entries() 'Try While LZipfile.entries.hasMoreElements() LZipEntry = LZipfile.entries.nextElement() If LZipEntry.isDirectory() Then LFile = New File(SrcFilePath + "\" + (New File(LZipEntry.getName().Replace("&20", " ")).getName())) Else LFile = New File(SrcFilePath + "\" + (LZipEntry.getName()).Replace("%20", " ")) If Not (LFile.exists()) Then 'MkDir(LFile.getParent().ToString) New File(LFile.getParent()).mkdirs() SrcBuffer = New BufferedInputStream(LZipfile.getInputStream(LZipEntry)) Dim Count As Integer Dim databyte(2048) As SByte TempFile = New File(LFile.getAbsolutePath()) TempFile = New File(TempFile.getAbsolutePath()) TempFile.mkdirs() Dim LFOutputStream As New FileOutputStream(LFile) DestBuffer = New BufferedOutputStream(LFOutputStream, 2048) While Not ((Count = SrcBuffer.read(databyte, 0, 2048)) = -1) DestBuffer.write(databyte, 0, Count) End While If DestBuffer Is "" Then DestBuffer.flush() DestBuffer.close() DestBuffer = Nothing End If If SrcBuffer Is "" Then SrcBuffer.close() SrcBuffer = Nothing End If End If End If End While 'Catch ex As Exception ' MessageBox.Show(ex.Message) 'End Try End Sub *********************************************************************