How to zip files in windows mobile 3.5?

1.1k views Asked by At

I'm trying to make a method of compressing file using Ionic.Zip.dll of DotNetZip.

Code for Compression:

using Ionic.Zip;
public string Compress(string[] Paths, string SaveFileName, string Password, string CompressionType)
    {
        try
        {
            using (ZipFile zip = new ZipFile())
            {
                if (Password != string.Empty)
                    zip.Password = Password;
                zip.CompressionLevel = Utility.GetCompressionLevel(CompressionType);
                foreach (string item in Paths)
                {
                    if (IsDirectory(item))
                        zip.AddDirectory(item);
                    else if (IsFile(item))
                        zip.AddFile(item);
                }
                zip.Save(SaveFileName);
            }
            return ExplorerResource.ResourceManager.GetString("ZipSuccess");
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }  

Custom class:

public class Utility
    {
        public static Ionic.Zlib.CompressionLevel GetCompressionLevel(string Expression)
        {
            Ionic.Zlib.CompressionLevel result = Ionic.Zlib.CompressionLevel.None;
            if (Ionic.Zlib.CompressionLevel.BestCompression.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.BestCompression;
            if (Ionic.Zlib.CompressionLevel.BestSpeed.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.BestSpeed;
            if (Ionic.Zlib.CompressionLevel.Default.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Default;
            if (Ionic.Zlib.CompressionLevel.Level0.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level0;
            if (Ionic.Zlib.CompressionLevel.Level1.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level1;
            if (Ionic.Zlib.CompressionLevel.Level2.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level2;
            if (Ionic.Zlib.CompressionLevel.Level3.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level3;
            if (Ionic.Zlib.CompressionLevel.Level4.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level4;
            if (Ionic.Zlib.CompressionLevel.Level5.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level5;
            if (Ionic.Zlib.CompressionLevel.Level6.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level6;
            if (Ionic.Zlib.CompressionLevel.Level7.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level7;
            if (Ionic.Zlib.CompressionLevel.Level8.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level8;
            if (Ionic.Zlib.CompressionLevel.Level9.ToString().ToUpper() == Expression.Trim().ToUpper())
                result = Ionic.Zlib.CompressionLevel.Level9;

            return result;
        }

GUI of ZIP program:

enter image description here

But I'm getting this error when I start compressing the file.

enter image description here

I think the code is not compatible with .net version?
I hope someone could make a solution for this, or if you have a better way of doing the method please tell me.. Thanks in advance!

2

There are 2 answers

0
competent_tech On BEST ANSWER

You need to download at least version 1.7 of dotnetzip and then use the compact framework-specific version (i.e. Ionic.Zip.CF.dll).

0
Aggis Wu On

I suggest that you can use Sevenzipsharp ,it was used by 7-zip , because it has a good performance. Sevenzipsharp on codeplex