精易论坛

标题: C# Zip压缩Class.cs [打印本页]

作者: stillness    时间: 2012-11-23 19:36
标题: C# Zip压缩Class.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9. namespace ClassLibrary1
  10. {
  11.     public class zip压缩Class
  12.     {
  13.         [DllImport("zip.dll", EntryPoint = "MyZip_AddFile")]
  14.         private static extern int MyZip_AddFile(string a, string b);
  15.         public bool 压缩文件(string 待压缩文件路径, string 目标文件路径)
  16.         {
  17.             int d = MyZip_AddFile(待压缩文件路径, 目标文件路径);
  18.             if (d > 0)
  19.             {
  20.                 return true;
  21.             }
  22.             else
  23.             {
  24.                 return false;
  25.             }
  26.         }
  27.         // zip 压缩文件
  28.         [DllImport("zip.dll", EntryPoint = "MyZip_AddDirectory")]
  29.         private static extern int MyZip_AddDirectory(string a, string b);
  30.         public bool 压缩目录(string 待压缩目录路径, string 目录输出路径)
  31.         {
  32.             int d = MyZip_AddDirectory(待压缩目录路径, 目录输出路径);
  33.             if (d > 0)
  34.             {
  35.                 return true;
  36.             }
  37.             else
  38.             {
  39.                 return false;
  40.             }
  41.         }
  42.         // zip 压缩目录
  43.         [DllImport("zip.dll", EntryPoint = "MyZip_ExtractFileAll")]
  44.         private static extern int MyZip_ExtractFileAll(string a, string b);
  45.         public bool 解压文件(string 压缩文件, string 文件输出路径)
  46.         {
  47.             int t = MyZip_ExtractFileAll(压缩文件, 文件输出路径);
  48.             if (t > 0)
  49.             {
  50.                 return true;
  51.             }
  52.             else
  53.             {
  54.                 return false;
  55.             }
  56.         }
  57.         // zip 解压文件
  58.         [DllImport("zip.dll", EntryPoint = "MyZip_GetLastError")]
  59.         private static extern int MyZip_GetLastError();
  60.         public bool 获取错误信息()
  61.         {
  62.             int d=MyZip_GetLastError()
  63.             if(d>0)
  64.             {
  65.                 return false;
  66.             }
  67.             else
  68.            {
  69.                 return true;               
  70.            }
  71.         }
  72.         // zip 获取错误信息
  73.     }
  74. }
复制代码
Zip压缩Class.rar (668 Bytes, 下载次数: 3)







欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4