Encoding of the Filename in AddEntry API

Oct 1, 2010 at 5:28 AM


I'm trying to archive a ZIP file using your great DotNetZip library (v. 1.9).The command I use is the following one:

zip.AddEntry(String.Format(@"data\{0}",ab.FileName), ab.RawText, Encoding.GetEncoding(ab.CharacterSet));

As you can see, I set the encoding for the content of the entry.

The name of the entry is the string:

"0135 290910 Dire GOVERNO MARINO BIOETICA NON È DI STATO, COSTITUZIONE È LA GUIDA (trasmessa alle ore 1401).xml"

While in the final zip file I find this string:

"0135 290910 Dire GOVERNO MARINO BIOETICA NON E DI STATO, COSTITUZIONE E LA GUIDA (trasmessa alle ore 1401).xml"

(I hope the HTML will not transform the example strings I wrote)

The strings are not the same and the character " E' " is translated to " E " (without quote).

I think is related to the encoding of the Filename. I set the encoding for the content of the entry to ISO-88591 but no the encoding for the name of the entry. Is it possibile to do this?

Do you have any idea on what could be the cause of this entry's name translation?

Thanks a lot


Oct 1, 2010 at 7:34 AM

Maybe I have found the solution....very easy:


ZipFile zip = new ZipFile(Encoding.UTF8) 


But I need your opinion beacuse I have to be sure that the entry name and comments will be in UTF8 while the content of the Entry will be in ISO-88591. Infact I use:


zip.AddEntry(String.Format(@"data\{0}",ab.FileName), ab.RawText, Encoding.GetEncoding(ab.CharacterSet)); 


Where ab.CharSet is ISO-88591.





Oct 5, 2010 at 12:54 PM
Yes, that is correct.

In the zip file format, The encoding of the filename is distinct and independent of the encoding of any file contents. By default the filenames and comments are encoded with IBM-437. The encoding of any entry content can be anything you specify.

By specifying UTF-8 for the encoding of the entry names and comments, you have a zipfile that can store an entry that has a filename with an (e with a grave accent) character. Be aware that not all applications and tools can read zipfiles that use UTF-8 encoding. See the documentation for more details.

Buon lavoro.