Dézipper avec SharpZipLib
Bonjour à tous
J'essaie de passer le pas de vb6 à vb.net ( Pas évident )
J'ai un probleme avec un fichier à dézziper
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Imports ICSharpCode
Imports ICSharpCode.SharpZipLib
Imports ICSharpCode.SharpZipLib.Zip
Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
Dim Redo As Integer = 1
Dim MyZipInputStream As ZipInputStream
Dim MyFileStream As FileStream
MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
Directory.CreateDirectory(ExtractDir)
While Not MyZipEntry Is Nothing
If (MyZipEntry.IsDirectory) Then
Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
Else
If Not Directory.Exists(ExtractDir & "\" & Path.GetDirectoryName(MyZipEntry.Name)) Then
Directory.CreateDirectory(ExtractDir & "\" & Path.GetDirectoryName(MyZipEntry.Name))
End If
MyFileStream = New FileStream(ExtractDir & "\" & MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
Dim count As Integer
Dim buffer(4096) As Byte
count = MyZipInputStream.Read(buffer, 0, 4096)
While count > 0
MyFileStream.Write(buffer, 0, count)
count = MyZipInputStream.Read(buffer, 0, 4096)
End While
MyFileStream.Close()
End If
Try
MyZipEntry = MyZipInputStream.GetNextEntry
Catch ex As Exception
MyZipEntry = Nothing
End Try
End While
If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ExtractArchive(FichierCharge, Chemin)
End Sub |
A l'execution j'ai une erreur à cette ligne au niveau de GetNextEntry
Code:
Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
http://gselve.free.fr/Capture.JPG
Si quelqu'un peut m'aider