Search code examples
c#compressionzipself-extracting

char extraction issue with ZipFile (System.IO.Compression), c# (WPF)


I am trying to extract a zip with multiple files. Some files have the "§" character in their names ("abc(§7)abc.txt"). When unpacking,

System.IO.Compression.ZipFile.ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName);

however, the '§' character is translated into the 'õ' (Latin Small Letter O with Tilde) character.

I have already tried to change the encoding. But there is only ASCII or UTF-8 (default)

System.IO.Compression.ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, Encoding entryNameEncoding);

Is someone able to show me the mistake?


Solution

  • Windows don't behave nicely with unicode file names inside zip. Using the Enconding 850 solves the problem.

    Encoding.GetEncoding(850);
    

    It looks like it got fixed in .Net framework 4.8 but I can't test it right now.

    Sources:

    https://devblogs.microsoft.com/oldnewthing/20180515-00/?p=98755 http://archives.miloush.net/michkap/archive/2012/01/04/10252916.html