user2917437
user2917437

Reputation: 81

ZipStorer not creating any file in Android c#

Hi i am using Xamarin with c# to make an app that can zip and unzip files so after a few tries i found zipStorer.

http://zipstorer.codeplex.com/

Here is my code

 ZipStorer zip = ZipStorer.Open(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/aaa.zip")), FileAccess.Read);

                List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                string path;

                foreach (ZipStorer.ZipFileEntry entry in dir)

                {

                    if (Path.GetFileName(entry.FilenameInZip) == "08.jpg")

                    {

                        path = Path.Combine(Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/")), Path.GetFileName(entry.FilenameInZip));

                        zip.ExtractFile(entry, Convert.ToString(Android.OS.Environment.GetExternalStoragePublicDirectory("BrSatisfacao/sample.jpg")));

                        break;

                    }   

                }

                zip.Close();

After a couple of hours the code is running fine and opening the zip and showing all in the console but no zip is being created... am i doing something wrong?

Upvotes: 1

Views: 545

Answers (1)

matthewrdev
matthewrdev

Reputation: 12190

Internally ZipStorer uses the character set 437 to do the encoding and un-encoding (line 85 in ZipStorer.cs):

    private static Encoding DefaultEncoding = Encoding.GetEncoding(437);

Xamarin does not include this character set by default when you build your application. As stated in the Localisation And Internationalisation document:

To reduce the size of the application, Xamarin.iOS doesn't include any specific encoding, and you have to instruct mtouch to include the assemblies containing the support for the encoding you need.

To include the character set, add the West character set through the internationalisation settings in your application:

enter image description here Ensure you check this for both Debug AND Release.

I could not get this to work for me when I was adding zip support to my application. In the end I rolled my own zip support by using the Java IO libraries but there may be a component available to add cross platform zip support.

Upvotes: 1

Related Questions