DotNetZip trouble with coding

2020-04-08 11:30发布

问题:

I am using DotNetZip. When i am archiving file which have english name all normally. but when i archiving file with russian names in result archive with bad names of file. Some peoplese said that string

ZipConstants.DefaultCodePage = 866;

But it not compile. I also use zip.UseUnicodeAsNecessary properties, and convert my file names to utf8 and utf7.

回答1:

To create a unicode zip file in DotNetZip:

using (var zip = new ZipFile())
{
   zip.UseUnicodeAsNecessary= true;
   zip.AddFile(filename, "directory\\in\\archive");
   zip.Save("archive.zip");
}

If you want a particular, specific code page, then you must use something else:

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

Check the documentation for those properties before using them!



回答2:

zip.AlternateEncodingUsage = ZipOption.Always;
zip.AlternateEncoding = Encoding.UTF8;


回答3:

try this

zip.AddEntry("yourfile.txt", "yourtext", Encoding.GetEncoding("utf-8"));

encoding type : encoding type info