Reputation: 5506
In C# my application running on Windows Server 2008 R2 I need to be able to extract any ZIP file created on Windows or MAC OSX. I am currently using the DotNetZip library.
But this library has trouble extracting MACOSX ZIP archives with special nordic characters in the filenames. I have tried specifying different encodings including macintosh in the Encoding.GetEncoding(string) method.
The Windows built-in zip tool also messes up the special characters. WinRAR 3.x does as well. But WinRAR 4.x seems to be the only tool that does the job right.
Is it at all possible to extract such a ZIP archive right with any available C# ZIP libraries?
UPDATE: Here is an example of a zip archive created with the default Zip function in Mac OSX. The first screen shot shows how the Windows Zip function cannot decode the filenames. The second screen shot shows the archive opened with WinRAR 4.11:
Download sample ZIP archive from Mac OSX
Upvotes: 0
Views: 2906
Reputation: 2163
Did you checkout SevenZipSharp
...
It uses 7-Zip dll to extract archives and IMO, 7-zip is the best archive handler..
I was digging into the Example zip and DotNetZip
.
With DotNetZip-WinFormsTool.exe
provided in the DotNetZip
binaries you can see every possible encoding in the DropDownBox
.
I tried some of them including UTF-8, Zip Default(IBM437), UTF-32, Unicode etc.
I got the best result with the UTF-8 Encoding...Same reading as WinRAR...
Moreover, IMO only WinRAR is using UTF-8 for all Archives whereas other Zip tools like 7-Zip, Explorer Default Zip Viewer use Zip Default encoding which enables them to read the filenames incorrectly!
So your best option is to Stick with DotNetZip
and use some codes like this :
using (ZipFile zf = new ZipFile(Application.StartupPath + "\\Arkiv.zip", new UTF8Encoding()))
{
zf.ExtractAll(Application.StartupPath + "\\Arkiv\\");
}
This code is tested to be working by me! Note that, after you extract the filenames will be shown in UTF8 formatting in the Explorer but if you open the zip file directly, explorer uses Zip Default Encoding.
Image Showing the DotNetZip
Tool in UTF-8 encoding :
For auto-detection of the Encoding
of a text you can refer to This SO Question
and This Code-Project Article
and UDE - C# port of Mozilla Universal Charset Detector
Upvotes: 2