我想在C# .net中使用PZKip压缩文件。我使用的是VS2008。你们谁能帮我做一个C# .net代码的例子。
发布于 2010-07-08 18:56:00
当你说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/
发布于 2010-07-08 19:22:57
如果你不想再使用PKZIP,也不想使用sharpziplib,.NET内置了压缩类:
http://msdn.microsoft.com/en-us/library/system.io.compression.aspx
发布于 2010-07-08 18:51:17
如果您必须使用PKZip,请尝试以下基本示例:
static void Main(string[] args)
{
var p = new Process();
p.StartInfo.FileName = @"Path to pkzip.exe";
p.StartInfo.Arguments = "the args";
p.Start();
}https://stackoverflow.com/questions/3202772
复制相似问题