0

When creating a zip file out of many Arabic named files, I have as prompted in DotNetZip's FAQ changed the code page to the following:

                  Using zip As New ZipFile()
                zip.AddDirectoryByName("Files")
                zip.AlternateEncoding = Encoding.UTF8
                zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always
                Dim row As Integer
                For row = 0 To ds.Tables("d").Rows.Count - 1

                    fileToDownload = Server.MapPath("~/.../Resources/Attachments/" + ds.Tables("d").Rows(row).Item(1).ToString)
                    zip.AddFile(fileToDownload, "Files")

                Next
                Response.Clear()
                Response.BufferOutput = False
                Dim zipName As String = [String].Format(gvRow.Cells(8).Text.Trim + ".zip")
                Response.ContentType = "application/zip"
                Response.AddHeader("content-disposition", "attachment; filename=" + zipName)
                zip.Save(Response.OutputStream)
                Response.[End]()

            End Using

I have used several listed Arabic encoding codes, but most of them produce '???' whereas this one produces names as the following: '¦ßs-¦ µ+++ ¦ß+pß.docx'

What is the correct code to be used? Or am I missing something?

Nal
  • 121
  • 2
  • 15

2 Answers2

3

Use UTF8 Encoding and pass it as parameter to the constructor:

IO.File.Delete("D:/testZip.zip")
Using zip As New Ionic.Zip.ZipFile(Encoding.UTF8)
      zip.AddDirectory("d:/out")
      zip.Save("D:/testZip.zip")
End Using

this code works with me with Arabic file names (windows 7).
EDIT #1 :
you must force DotNetZip to use the specified encoding by using Always option instead of AsNesseary :

 IO.File.Delete("D:/testZip.zip")
  Using zip As New Ionic.Zip.ZipFile()
            zip.AlternateEncoding = Encoding.UTF8
            zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always
            zip.AddDirectory("d:/out")
            zip.Save("D:/testZip.zip")
  End Using

EDIT #2 :
based on your comment, I think your operating system does not support Arabic UI,for windows 7 professional 32 bit, go to Control Panel -> Region and Language -> Administrative [tab] -> click "change System locale" button -> choose "Arabic Egypt" for Example -> OK -> OK (restart computer is needed) , Don't worry, the language of windows 7 still English.
EDIT #3 :
As I mentioned in EDIT #2, your system must support Arabic UI, for example, create a file called (ملف جديد) then add it to archive using WinZip or Winrar, then open the generated archive, if you can read file names correctly , then try to use one of the following encodings in your code :

Encoding.Unicode
Encoding.UTF7
Encoding.UTF8
Encoding.UTF32

If you are unable to read Arabic file names inside the generated archive, you must configure your system to support Arabic UI.
Also, please use the following order for these lines, put the Encoding, then add files or folders :

zip.AlternateEncoding = Encoding.UTF8
zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.Always
zip.AddDirectoryByName("Files")
houssam
  • 1,823
  • 15
  • 27
  • Still not working. Would you like to take a look at the complete code block? – Nal Dec 16 '14 at 09:40
  • @Nal : yes post the full code .. Q: if you compress a folder with Arabic file names by WinZip or WinRar, do you see the correct names after opening the Archive? – houssam Dec 16 '14 at 09:45
  • Nope, they're all symbols. And posted. – Nal Dec 16 '14 at 09:45
  • @Nal : I tested the code, it works correctly and display Arabic names, I update the answer, See EDIT #2. – houssam Dec 16 '14 at 10:05
  • OK so it works in way that it changed the characters to a mixture of Arabic and symbols. (I tried several Arabic options, all the same) – Nal Dec 16 '14 at 10:17
  • @Nal : hope to find help from other members. – houssam Dec 16 '14 at 10:33
  • My OS is 64 bit. Does it change anything? – Nal Dec 16 '14 at 11:27
  • @Nal: I think that it is similar to 32 bit, See Edit #3 in answer. – houssam Dec 16 '14 at 12:05
  • The system supports, as compressing into WinRar hasn't changed the characters. Whereas changing the Encoding drastically changes the characters (obviously). None of the four works. I appreciate your tolerance, it's really on my nerves \: Not even code page 864. – Nal Dec 17 '14 at 05:29
  • Never mind, I got it! Your answers were helpful though. – Nal Dec 17 '14 at 05:46
2

After using what seemed like a myriad of trials using code pages, simply replacing this:

                zip.AlternateEncoding = Encoding.UTF8

with this:

                zip.AlternateEncoding = Encoding.GetEncoding(720)

worked.

Nal
  • 121
  • 2
  • 15
  • [Code page 720](http://en.wikipedia.org/wiki/Code_page_720) : Code page 720 is a code page used under MS-DOS to write Arabic. – houssam Dec 17 '14 at 06:48
  • @houssam yep! Apparently there are at least ten codes for Arabic of which I found. Thank you for your efforts. – Nal Dec 17 '14 at 06:49