我使用WinZIP+WZCLINE和WinRAR做的。
/// <summary>
/// 压缩文件并删除源文件
/// </summary>
private void CompressFile()
{
Process proc = new Process();
proc.StartInfo.WorkingDirectory = writePath;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false; switch(compressType)
{
case ".zip":
proc.StartInfo.FileName = @"C:\Program Files\WinZip\wzzip.exe";
proc.StartInfo.Arguments = "" + compressFileName + " " + fileName;
break;
case ".exe":
proc.StartInfo.FileName = @"C:\Program Files\WinRAR\rar.exe";
proc.StartInfo.Arguments = " a -df -sfxC:\\\"Program Files\"\\WinRAR\\default.sfx " + compressFileName + " " + fileName;
break;
case ".rar":
proc.StartInfo.FileName = @"C:\Program Files\WinRAR\rar.exe";
proc.StartInfo.Arguments = " a -df " + compressFileName + " " + fileName;
break;
default:
break;
} proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
try
{
proc.Start();
}
catch
{
}
proc.WaitForExit();
if(proc.ExitCode == 0)
{
}
else
{
}
}

解决方案 »

  1.   

    楼上的对我的帮助不是很大,还是谢谢。
    有对ziplib比较熟悉的吗?帮忙解答一下,谢谢~~
      

  2.   

    这是我以前写的一个简单包装 可能对你有帮助 public static MemoryStream UnZipStream(MemoryStream zipedStream)
    {
    MemoryStream outStream=new MemoryStream();
    zipedStream.Seek(0,SeekOrigin.Begin);
    ZipInputStream s=new ZipInputStream(zipedStream);
    ZipEntry theEntry;
    if ((theEntry = s.GetNextEntry()) != null) 
    {
    int size = 2048;
    byte[] data = new byte[2048];
    while (true) 
    {
    size = s.Read(data, 0, data.Length);
    if (size > 0) 
    {
    outStream.Write(data, 0, size);

    else 
    {
    break;
    }
    }
    }
    return outStream;
    } public static void UnZip(string[] args)
    {
    ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
      
    ZipEntry theEntry;
    while ((theEntry = s.GetNextEntry()) != null) 
    {
       
    string directoryName = Path.GetDirectoryName(args[1]);
    string fileName      = Path.GetFileName(theEntry.Name);
       
    //生成解压目录
    Directory.CreateDirectory(directoryName);
       
    if (fileName != String.Empty) 
    {   
    //解压文件到指定的目录
    FileStream streamWriter = File.Create(args[1]+theEntry.Name);
        
    int size = 2048;
    byte[] data = new byte[2048];
    while (true) 
    {
    size = s.Read(data, 0, data.Length);
    if (size > 0) 
    {
    streamWriter.Write(data, 0, size);

    else 
    {
    break;
    }
    }
        
    streamWriter.Close();
    }
    }
    s.Close();
    }                  public static MemoryStream UnZipFile(string inFile)
    {
    MemoryStream outStream=new MemoryStream();
    ZipInputStream s=new ZipInputStream(File.OpenRead(inFile));
    ZipEntry theEntry;
    if ((theEntry = s.GetNextEntry()) != null) 
    {
    int size = 2048;
    byte[] data = new byte[2048];
    while (true) 
    {
    size = s.Read(data, 0, data.Length);
    if (size > 0) 
    {
    outStream.Write(data, 0, size);

    else 
    {
    break;
    }
    }
    }
    s.Close();
    return outStream;
    }
      

  3.   

    To gully() :请问你的zipedStream是用什么方法压缩的,我解压的函数也是这样写的,但是我传入压缩后的流提示错误无法读取。