Having problem with Danish character ø

Oct 12, 2009 at 9:29 AM

Hi,

I am trying to create a zip file of text files. The zip file contains Danish characters in filenames and also in textfiles. but when i create the file the danish character "ø" is converted to "o". I have also tried different options for 

ZipFile.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");

filename "infø.txt" changes to "Inf°.txt"

ZipFile.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(1252);

filename "infø.txt" changes to "Inf°.txt"

ZipFile.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(850);

filename "infø.txt" changes to "Inf¢.txt"

ZipFile.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding(850);

filename "infø.txt" changes to "Info.txt"

ZipFile.ProvisionalAlternateEncoding = System.Text.Encoding.Default;

filename "infø.txt" changes to "Info.txt"

also tried the work item http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7791

Entries in my Web.config  for encoding are:

<font size="2" color="#0000ff"><font size="2" color="#0000ff">

<

</font></font><font size="2" color="#0000ff">

 

</font>

globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" fileEncoding="ISO-8859-1" culture="en-GB"/>

 

following is the code for generating zip file.

Response.Clear();

Response.ContentType ="application/zip";

<font size="2">

Response.AddHeader(

</font>"content-disposition", "attachment; filename=Graveringsordre.zip");

"content-disposition", "attachment; filename=Graveringsordre.zip");

using (ZipFile zip = new Ionic.Zip.ZipFile())
            {
	     // I tried different encoding options as specified above
              zip.ProvisionalAlternateEncoding = System.Text.Encoding.Default;
              #region Add Strings in Text files and zip them

              // code for adding text files
              zip.AddFileFromString("Infø.txt", "Graveringsordre", sb_Info.ToString());
              zip.AddFileFromString("navne.txt", "Graveringsordre", sb_1.ToString());
              zip.Save(Response.OutputStream);
            }
            Response.End();            
Please tell me where I am doing anything wrong?
Thanks in advance.
Best regards,
Qaisar
Coordinator
Oct 12, 2009 at 10:00 AM

Q, how do you unzip?  What tool are you using?

How do you determine that the filename "changes"?

 

Coordinator
Oct 12, 2009 at 10:37 AM

Did you read the doc on ProvisionalAlternateEncoding ?  If not, I suggest you do that now.

Any zip file that you produce using ProvisionalAlternateEncoding will be non-compliant, if the encoding is not one of (UTF-8, IBM437).  And, when reading such a zip file, you need to specify to the zip tool or library which encoding was used to create the zip file.  This is explained in the doc.

Suppose you create a zipfile, that contains entries with filenames that have Danish characters.  If you use encoding iso-8859-1, the filenames will be correctly encoded in the zip.  But, to read that zipfile correctly, you have to specify the same codepage at the time you read it.  In other words, if you explicitly specify the codepage when you create the zipfile, you must explicitly specify the same codepage when reading the zipfile.  The way you specify the code page varies depending on the tool or library you use to read the zip.  In DotNetZip, it's a parameter on the ZipFile constructor.   It isn't possible with windows explorer, as far as I know, to specify an explicit codepage.  Maybe that is why you are not getting the results you expect.   If try to read that zip file with Windows Explorer or another application that is not flexible with respect to the codepage used to decode filenames in zipfiles, you will get a filename like "Inf°.txt".

To get what you want, use the property UseUnicodeAsNecessary - this produces a UTF-8 encoded zipfile, which is compliant. It will be readable with compliant zip tools. 

like so:

    using (ZipFile zip = new Ionic.Zip.ZipFile())
    {
        // zip.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
        zip.UseUnicodeAsNecessary = true;

        // code for adding text files
        zip.AddEntry("Infø.txt", "Graveringsordre", s1);
        zip.AddEntry("navne.txt", "Graveringsordre", s2);

        zip.Save( ... );
    }

If you find that doesn't work, with whatever you use to read your zip files,, then you can use zip.ProvisionalAlternateEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");,  but you must also specify that code page when you read the zipfile, in the tool you use to read it.

I wrote a bunch of material discussing codepages, compliance, and interoperability.  It's all in the documentation.

Good luck.

 

Oct 12, 2009 at 11:08 AM
Edited Oct 12, 2009 at 11:35 AM

Dear Chesso,

Thank You very much for the good work and quick reply.

Its my fault. Actually I had winrar3.40 installed on my computer. I updated to the latest version and now its working fine.

Your DotNetZip library is fantastic.

ThankYou very much for the help.

Best Regards,

Qaisar