使用PKZIP压缩文件的C#.net代码

使用PKZIP压缩文件的C#.net代码,c#,C#,我想在C#net中使用PZKip压缩一个文件。我用的是VS2008。请你们中的任何一位帮我举一个C#.net代码示例。如果必须使用PKZip,请尝试以下基本示例: static void Main(string[] args) { var p = new Process(); p.StartInfo.FileName = @"Path to pkzip.exe"; p.StartInfo.Arguments

我想在C#net中使用PZKip压缩一个文件。我用的是VS2008。请你们中的任何一位帮我举一个C#.net代码示例。

如果必须使用PKZip,请尝试以下基本示例:

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

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

当你说PKZip时,这是否意味着你实际上拥有可执行文件,并且你想用它来压缩文件?如果是这种情况,您可以通过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#to ZIP格式编程压缩文件,我建议你抓取SharpZipLib。它支持多种格式,包括Zip、Gzip、BZip2和Tar。它附带了示例代码,并且是开源的


您可以在这里获取它:

以防您不想再使用PKZIP,也不想使用sharpziplib,.NET内置了压缩类:


是否必须使用pkzip?例如,有免费的zip库可用