2010-07-08 63 views
1

我想用C#.net中的PZKip压缩文件。我正在使用VS 2008.你们中的任何一个人都可以用C#.net代码示例来帮助我。C#.net代码用于使用PKZIP压缩文件

+2

它是否必须与pkzip?有免费的zip库可用,例如http://dotnetzip.codeplex.com/ – 2010-07-08 10:50:06

回答

1

当你说的PKZip,这是否意味着你确实有可执行文件,你想用它来ZIP文件?如果是这样的话,你可以通过C#,而方便地调用EXE:

ProcessStartInfo startInfo = new ProcessStartInfo("pkzip.exe", "output.zip /add file1.txt file2.jpg file3.png"); 
startInfo.CreateNoWindow = true; // Let's not show the DOS box 

// Execute the process 
Process zipProcess = Process.Start(startInfo); 
zipProcess.WaitForExit(); 

我不知道是什么的参数,具体而言,是PKZIP,但你也许可以明白这一点很容易。

现在,如果另一方面你问的是如何以C#格式压缩一个文件到ZIP格式,我建议你抓取SharpZipLib。它支持多种格式,包括Zip,Gzip,BZip2和Tar。它带有示例代码,它是开源的。

你可以在这里抓住它:http://www.icsharpcode.net/opensource/sharpziplib/

0

如果你必须使用的PKZip那就试试这个简单的例子:

static void Main(string[] args) 
     { 
      var p = new Process(); 

      p.StartInfo.FileName = @"Path to pkzip.exe"; 
      p.StartInfo.Arguments = "the args"; 
      p.Start(); 
     }