DotNetZip trouble with coding

2020-04-08 12:08发布

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.

3条回答
不美不萌又怎样
2楼-- · 2020-04-08 12:14
zip.AlternateEncodingUsage = ZipOption.Always;
zip.AlternateEncoding = Encoding.UTF8;
查看更多
乱世女痞
3楼-- · 2020-04-08 12:14

try this

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

encoding type : encoding type info

查看更多
Emotional °昔
4楼-- · 2020-04-08 12:36

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!

查看更多
登录 后发表回答