We use ASP.NET core and have this code:
public static void Compress(string sourceDirectoryName, string destinationArchiveFileName)
{
    var directoryName = Path.GetFileName(sourceDirectoryName);
    var remotePath = sourceDirectoryName.Split(new[] { directoryName }, StringSplitOptions.RemoveEmptyEntries).First();
    using (var zipStream = new MemoryStream())
    {
        using (var zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true, Encoding.UTF8))
        {
            zip.CreateEntry(string.Concat(directoryName, directorySlash));
            foreach (var path in Directory.EnumerateFileSystemEntries(sourceDirectoryName, "*", SearchOption.AllDirectories))
            {
                if (!Directory.Exists(path))
                    zip.CreateEntryFromFile(path, path.RemoveSubString(remotePath).ReplacePathSeparatorOnSlash());
                else
                    zip.CreateEntry(string.Concat(path.RemoveSubString(remotePath).ReplacePathSeparatorOnSlash(), directorySlash));
            }
        }
        using (var outputZip = new FileStream(destinationArchiveFileName, FileMode.Create))
        {
            zipStream.Seek(0, SeekOrigin.Begin);
            zipStream.CopyTo(outputZip);
        }
    }
}
After zipping sourceDirectoryName that contains russian symbols if we open this archive with windows explorer, we see the following:
 and where the name marked with green is correct, and the name marked with red has its name encoding changed.
and where the name marked with green is correct, and the name marked with red has its name encoding changed.
If we use the following code:
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName);
We have the same problem. How to fix this problem?
I have found answer. I have to use encoding 866:
using (var zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true, Encoding.GetEncoding(866)))
{
    ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With