Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNetZip trouble with russian encoding

Tags:

c#

.net

dotnetzip

i use DotNetZip in my project.

using (var zip = new ZipFile()) 
{ 
   zip.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(866); 
   zip.AddFile(filename, "directory\\in\\archive"); 
   zip.Save("archive.zip"); 
} 

all ok but when i use method AddDirectoryByName i have a bad directory names.

like image 263
Xaver Avatar asked Apr 19 '10 06:04

Xaver


3 Answers

Universal way for all is :

zip.AlternateEncoding = Encoding.UTF8;
zip.ProvisionalAlternateEncoding = Encoding.GetEncoding(Console.OutputEncoding.CodePage);
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
like image 100
Pawel Niemczyk Avatar answered Nov 16 '22 14:11

Pawel Niemczyk


This way in new version work for me

zip.AlternateEncodingUsage = ZipOption.Always;
zip.AlternateEncoding = Encoding.GetEncoding(866); 
like image 5
Igor Semin Avatar answered Nov 16 '22 13:11

Igor Semin


You may Peek Definition first. Then you will find this:

public ZipFile(Encoding encoding);

So you can use this:

using (ZipFile zip = new ZipFile(Encoding.UTF8))
like image 3
Tsai Jing Sien Avatar answered Nov 16 '22 12:11

Tsai Jing Sien