We use the ASP.NET kernel 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 containing Russian characters, if we open this archive using Windows Explorer, we will see the following:
and where the name marked in green is correct and the name marked in red has changed its encoding of the name.
If we use the following code:
ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName);
We have the same problem. How to solve this problem?
source share