我想在C#.net中使用PZKip压缩文件。我正在使用VS 2008.你们中的任何一个人都可以用C#.net代码示例帮助我。
答案 0 :(得分:2)
当你说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#编程压缩文件到ZIP格式,我建议你抓住 SharpZipLib 。它支持多种格式,包括Zip,Gzip,BZip2和Tar。它带有示例代码,它是开源的。
你可以在这里抓住它:http://www.icsharpcode.net/opensource/sharpziplib/
答案 1 :(得分:1)
如果你不想再使用PKZIP并且你不想使用sharpziplib,.NET内置了压缩类:
http://msdn.microsoft.com/en-us/library/system.io.compression.aspx
答案 2 :(得分: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();
}