-2

please tell me, how do I implement Encoding.GetEncoding ( "cp866")? In the course of export from archive the Russian symbols aren't correctly displayed.

public static class ZipArchiveExtension
{
    public static void ExtractToDirectory(this ZipArchive archive, string destinationDirectoryName, bool overwrite)
    {
        if (!overwrite)
        {
            archive.ExtractToDirectory(destinationDirectoryName);
            return;
        }
        foreach (ZipArchiveEntry file in archive.Entries)
        {
            string completeFileName = Path.Combine(destinationDirectoryName, file.FullName);
            if (file.Name == "")
            {
                Directory.CreateDirectory(Path.GetDirectoryName(completeFileName));
                continue;
            }
            file.ExtractToFile(completeFileName, true);
        }
    }
}

FileStream zipToOpen = new FileStream(zipPath, FileMode.Open);
ZipArchive archive = new ZipArchive(zipToOpen);
ZipArchiveExtension.ExtractToDirectory(archive, extractPath, true);
zipToOpen.Dispose();

As in System.IO.Compression: ZipFile.ExtractToDirectory(zipPath, extractPath, Encoding.GetEncoding("cp866"));

aaa
  • 121
  • 1
  • 6

1 Answers1

2

In order to use a specific encoding on a ZipArchive, it needs to be specified in the constructor.

You should be able to use the 4 argument constructor:

ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, false, Encoding.GetEncoding("cp866"));

https://msdn.microsoft.com/en-us/library/hh875101(v=vs.110).aspx

Eris
  • 7,378
  • 1
  • 30
  • 45