Bonjour,
Dans un WindowsForm, j'utilise ICSharpCode.SharpZipLib pour créer un fichier Zip protégé par mot de passe.
Je le fais à l'aide des fonctions ci-dessous, et tout fonctionne à merveille à part un problème sur les fichiers qui ont un nom accentué.
En effet, dans l'archive, ceux-ci ont des noms "abimés" :
Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 Public Sub CreerArchive(outPathname As String, password As String, folderName As String) Using fsOut As FileStream = File.Create(outPathname) Using zipStream As New ZipOutputStream(fsOut) zipStream.SetLevel(3) zipStream.Password = password Dim folderOffset As Integer = folderName.Length + (If(folderName.EndsWith("\"), 0, 1)) CompressFolder(folderName, zipStream, folderOffset) End Using End Using End Sub
Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
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 Private Sub CompressFolder(path As String, zipStream As ZipOutputStream, folderOffset As Integer) Dim files As String() = Directory.GetFiles(path) For Each filename As String In files Dim fi As New FileInfo(filename) Dim entryName As String = filename.Substring(folderOffset) entryName = ZipEntry.CleanName(entryName) Dim newEntry As New ZipEntry(entryName) newEntry.DateTime = fi.LastWriteTime newEntry.Size = fi.Length zipStream.PutNextEntry(newEntry) Dim buffer As Byte() = New Byte(4095) {} Using streamReader As FileStream = File.OpenRead(filename) StreamUtils.Copy(streamReader, zipStream, buffer) End Using zipStream.CloseEntry() Next Dim folders As String() = Directory.GetDirectories(path) For Each folder As String In folders CompressFolder(folder, zipStream, folderOffset) Next End Sub
Auriez-vous une idée de comment régler ce problème qui est très embêtant...
J'ai fait un tour sur Google concernant ZipEntry.CleanName mais je n'ai rien trouvé de probant.
Merci d'avance
Partager