DotNetZip trouble with coding

杀马特。学长 韩版系。学妹 提交于 2019-12-19 21:24:25

问题


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



来源:https://stackoverflow.com/questions/2565414/dotnetzip-trouble-with-coding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!