开发者

C# .net code for zipping a file using PKZIP

开发者 https://www.devze.com 2023-01-06 06:14 出处:网络
I want to zip a file using PZKip in C# .net. I am using VS 2008. Can any one o开发者_如何学Pythonf you please help me with a C# .net code example.When you say PKZip, does that mean you actually have t

I want to zip a file using PZKip in C# .net. I am using VS 2008. Can any one o开发者_如何学Pythonf you please help me with a C# .net code example.


When you say PKZip, does that mean you actually have the executable and you want to use that to ZIP a file? If that's the case, you can call the EXE through C# rather easily:

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();

I don't know what the parameters, specifically, are for pkzip, but you can probably figure that out quite easily.

Now, if on the other hand you're asking about how to compress a file programmatically in C# to ZIP format, I would recommend you grab SharpZipLib. It supports several formats, including Zip, Gzip, BZip2, and Tar. It comes with sample code and it's open source.

You can grab it here: http://www.icsharpcode.net/opensource/sharpziplib/


Just in case you don't want to use PKZIP anymore and you don't want to use sharpziplib, .NET has built in compression classes:

http://msdn.microsoft.com/en-us/library/system.io.compression.aspx


If you must use PKZip then try this basic example:

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

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

精彩评论

暂无评论...
验证码 换一张
取 消