1

I want to zip a file using PZKip in C# .net. I am using VS 2008. Can any one of you please help me with a C# .net code example.

user386527
  • 125
  • 1
  • 5

3 Answers3

2

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/

rakuo15
  • 889
  • 6
  • 11
1

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

0

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();
        }
Jason Evans
  • 28,906
  • 14
  • 90
  • 154