DotNetZip Encoding Issues

I am using DotNetZip. When I archive a file with an English name, everything is fine. but when I archive the file with Russian names into the archive of results with bad file names. Some people said that the line

ZipConstants.DefaultCodePage = 866;

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

+3
source share
3 answers

To create a zip file in Unicode in DotNetZip:

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

If you need a specific specific code page, you should 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 these properties before using them!

+8
source
zip.AlternateEncodingUsage = ZipOption.Always;
zip.AlternateEncoding = Encoding.UTF8;
+16
source

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

:

+2

Source: https://habr.com/ru/post/1739573/


All Articles