简体   繁体   English

如何在Windows Mobile 3.5中压缩文件?

[英]How to zip files in windows mobile 3.5?

I'm trying to make a method of compressing file using Ionic.Zip.dll of DotNetZip. 我正在尝试使用Ionic.Zip.dll的Ionic.Zip.dll压缩文件的方法。

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: ZIP程序的GUI:

在此处输入图片说明

But I'm getting this error when I start compressing the file. 但是,当我开始压缩文件时出现此错误。

在此处输入图片说明

I think the code is not compatible with .net version? 我认为代码与.net版本不兼容?
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! 我希望有人可以为此解决方案,或者如果您有更好的方法,请告诉我。

您需要至少下载dotnetzip的 1.7版本,然后使用紧凑的框架特定版本(即Ionic.Zip.CF.dll)。

I suggest that you can use Sevenzipsharp ,it was used by 7-zip , because it has a good performance. 我建议您可以使用Sevenzipsharp,它被7-zip使用,因为它具有良好的性能。 Sevenzipsharp on codeplex Codeplex上的Sevenzipsharp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测Windows Mobile 5设备序列号? (.NET CF 3.5) - How to detect Windows Mobile 5 Device Serial Number? (.NET CF 3.5) 如何使用.Net CF 3.5获取PDA / Windows Mobile的用户名? - How to get the UserName of the PDA/Windows Mobile using .Net CF 3.5? Windows Mobile的7-Zip问题 - 7-Zip Problem for windows mobile 是否可以在Windows Mobile(3.5)上打开2连接? - Is it possible to open 2 connection on Windows mobile (3.5)? 如何使用c#.net,windowsce,.net3.5框架,Windows Mobile 6 Professional将滚动条应用于Windows Mobile应用程序 - How to apply scrollbar to windows mobile application using c#.net, windowsce, .net3.5 framework, windows mobile 6 professional 如何在Windows Phone 8中创建多个文件(NOT FOLDER)的zip - How to create zip of multiple files (NOT FOLDER) in Windows Phone 8 如何检测用户何时单击Windows Mobile(.NET CF 3.5)中的通知图标 - How can you detect when the user clicks on the notification icon in Windows Mobile (.NET CF 3.5) 如何从 c# 中的类文件更新窗体 GUI for windows CE (Windows Mobile 6.5.3 ) CF 3.5 设备 - How to update the form GUI from a class file in c# for windows CE (Windows Mobile 6.5.3 ) Devices with CF 3.5 C#.Net Compact Framework 3.5 FtpWebRequest Windows Mobile 6 - C# .Net Compact Framework 3.5 FtpWebRequest Windows Mobile 6 如何在.NET 3.5中使用DotNetZip提取zip文件? - How can I extract a zip file with DotNetZip in .NET 3.5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM