private void btnSimpleZip_Click(object sender, System.EventArgs e) { textBox1.Text = string.Empty; textBox2.Text = string.Empty; //Set up the files array string [] files = new string[2]; //NOTE: //Change these file names to whatever is appropriate //on your system files[0] = @"c:\tmp\testzipfile1.rtf"; files[1] = @"c:\tmp\testzipfile2.rtf"; //Instantiate the Zip object m_ZipObj = new Zip(); //Set the Zip object properties m_ZipObj.FilesToZip = files; m_ZipObj.Verbose = VerboseMessagesEnum.True; m_ZipObj.Level = CompressionLevelEnum.Level6; //This is optional. This is how to add a comment m_ZipObj.Comment = "Test Comment"; m_ZipObj.CommentOption = CommentEnum.True; //NOTE: //File name of the resulting zip file. Change this as appropriate m_ZipObj.ZipFileName = @"c:\tmp\zip\csharpzip.zip"; //Wire the event handlers to receive the events from the Zip class m_ZipObj.ReceivePrintMessage += new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); m_ZipObj.ReceiveServiceMessage += new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); btnStop.Enabled = true; //Zip the files int ret = m_ZipObj.ZipFiles(); //Examine the return code MessageBox.Show("Done. Return Code: " + ret.ToString()); }
private void btnSimpleZip_Click(object sender, System.EventArgs e) { textBox1.Text = string.Empty; textBox2.Text = string.Empty; //Set up the files array string [] files = new string[2]; //NOTE: //Change these file names to whatever is appropriate //on your system files[0] = @"c:\tmp\testzipfile1.rtf"; files[1] = @"c:\tmp\testzipfile2.rtf"; //Instantiate the Zip object m_ZipObj = new Zip(); //Set the Zip object properties m_ZipObj.FilesToZip = files; m_ZipObj.Verbose = VerboseMessagesEnum.True; m_ZipObj.Level = CompressionLevelEnum.Level6; //This is optional. This is how to add a comment m_ZipObj.Comment = "Test Comment"; m_ZipObj.CommentOption = CommentEnum.True; //NOTE: //File name of the resulting zip file. Change this as appropriate m_ZipObj.ZipFileName = @"c:\tmp\zip\csharpzip.zip"; //Wire the event handlers to receive the events from the Zip class m_ZipObj.ReceivePrintMessage +=new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); m_ZipObj.ReceiveServiceMessage +=new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); btnStop.Enabled = true; //Zip the files int ret = m_ZipObj.ZipFiles(); //Examine the return code MessageBox.Show("Done. Return Code: " + ret.ToString()); }
private void btnZipRecurse_Click(object sender, System.EventArgs e) { //NOTE: //Consult the zip32 limits provided in the documentation textBox1.Text = string.Empty; textBox2.Text = string.Empty; //Instantiate the Zip object m_ZipObj = new Zip(); //_____________________________________________________________________________ //WORK AROUND: //The InfoZip documentation states that the zip32.dll can recurse directories if the -r or -R flag is specified. //In code this is specified by setting the fRecurse flag of the ZPOPT structure to 1 (-r) or 2 (-R). //However, in my test, when I specified either of the recurse flags I frequently received errors coming //back from the ZpArchive function. My work around is to recurse the specified directories and prepare //an array of file names and pass that array to zip32. Everything seems to work OK if I do this. //If you want to try the recurse option, below is an example of how to do it. // string [] files = new string[1]; // // //NOTE: // //Change this to whatever is appropriate // System.IO.Directory.SetCurrentDirectory(@"C:\TmpTest"); // // //Specify the file mask you want to use. Consult the zip32.dll documentation for the // //-r and -R options // files[0] = @"*.*"; // // m_ZipObj.FilesToZip = files; // m_ZipObj.Recurse = RecurseEnum.Level2; // m_ZipObj.Verbose = VerboseMessagesEnum.True; // m_ZipObj.Level = CompressionLevelEnum.Level6; // // //NOTE: // //File name of the resulting zip file. Change this as appropriate // m_ZipObj.ZipFileName = @"c:\tmp\zip\csharprecurse.zip"; // // //Wire the event handlers to receive the events from the Zip class // m_ZipObj.ReceivePrintMessage +=new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); // m_ZipObj.ReceiveServiceMessage +=new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); // // btnStop.Enabled = true; // // //Zip the files // int ret = m_ZipObj.ZipFiles(); // // //Examine the return code // MessageBox.Show("Done. Ret: " + ret.ToString()); //_____________________________________________________________________________ //Prepare an array of all the files in the directory //NOTE: //Change this to whatever is appropriate string root = @"C:\Tmp\TestZip"; ArrayList fileList = new ArrayList(); RecurseGetDirsAndFiles(root, fileList); fileList.TrimToSize(); //Build the files array. Practically, the .NET limit here is your RAM string [] files = new string[fileList.Count]; int idx = 0; IEnumerator en = fileList.GetEnumerator(); while ( en.MoveNext() ) { files[idx] = en.Current.ToString(); idx++; } //Set the Zip object properties m_ZipObj.FilesToZip = files; m_ZipObj.Verbose = VerboseMessagesEnum.True; m_ZipObj.Level = CompressionLevelEnum.Level6; //This is optional. This is how to add a comment m_ZipObj.Comment = "Test Comment"; m_ZipObj.CommentOption = CommentEnum.True; //NOTE: //File name of the resulting zip file. Change this as appropriate m_ZipObj.ZipFileName = @"c:\tmp\zip\csharpzip2.zip"; //Wire the event handlers to receive the events from the Zip class m_ZipObj.ReceivePrintMessage +=new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); m_ZipObj.ReceiveServiceMessage +=new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); btnStop.Enabled = true; //Zip the files int ret = m_ZipObj.ZipFiles(); //Examine the return code MessageBox.Show("Done. Ret: " + ret.ToString()); }
private void btnZipRecurse_Click(object sender, System.EventArgs e) { //NOTE: //Consult the zip32 limits provided in the documentation textBox1.Text = string.Empty; textBox2.Text = string.Empty; //Instantiate the Zip object m_ZipObj = new Zip(); //_____________________________________________________________________________ //WORK AROUND: //The InfoZip documentation states that the zip32.dll can recurse directories if the -r or -R flag is specified. //In code this is specified by setting the fRecurse flag of the ZPOPT structure to 1 (-r) or 2 (-R). //However, in my test, when I specified either of the recurse flags I frequently received errors coming //back from the ZpArchive function. My work around is to recurse the specified directories and prepare //an array of file names and pass that array to zip32. Everything seems to work OK if I do this. //If you want to try the recurse option, below is an example of how to do it. // string [] files = new string[1]; // // //NOTE: // //Change this to whatever is appropriate // System.IO.Directory.SetCurrentDirectory(@"C:\TmpTest"); // // //Specify the file mask you want to use. Consult the zip32.dll documentation for the // //-r and -R options // files[0] = @"*.*"; // // m_ZipObj.FilesToZip = files; // m_ZipObj.Recurse = RecurseEnum.Level2; // m_ZipObj.Verbose = VerboseMessagesEnum.True; // m_ZipObj.Level = CompressionLevelEnum.Level6; // // //NOTE: // //File name of the resulting zip file. Change this as appropriate // m_ZipObj.ZipFileName = @"c:\tmp\zip\csharprecurse.zip"; // // //Wire the event handlers to receive the events from the Zip class // m_ZipObj.ReceivePrintMessage +=new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); // m_ZipObj.ReceiveServiceMessage +=new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); // // btnStop.Enabled = true; // // //Zip the files // int ret = m_ZipObj.ZipFiles(); // // //Examine the return code // MessageBox.Show("Done. Ret: " + ret.ToString()); //_____________________________________________________________________________ //Prepare an array of all the files in the directory //NOTE: //Change this to whatever is appropriate string root = @"C:\Tmp\TestZip"; ArrayList fileList = new ArrayList(); RecurseGetDirsAndFiles(root, fileList); fileList.TrimToSize(); //Build the files array. Practically, the .NET limit here is your RAM string [] files = new string[fileList.Count]; int idx = 0; IEnumerator en = fileList.GetEnumerator(); while (en.MoveNext()) { files[idx] = en.Current.ToString(); idx++; } //Set the Zip object properties m_ZipObj.FilesToZip = files; m_ZipObj.Verbose = VerboseMessagesEnum.True; m_ZipObj.Level = CompressionLevelEnum.Level6; //This is optional. This is how to add a comment m_ZipObj.Comment = "Test Comment"; m_ZipObj.CommentOption = CommentEnum.True; //NOTE: //File name of the resulting zip file. Change this as appropriate m_ZipObj.ZipFileName = @"c:\tmp\zip\csharpzip2.zip"; //Wire the event handlers to receive the events from the Zip class m_ZipObj.ReceivePrintMessage += new ZipDLLPrintMessageEventHandler(zipObj_ReceivePrintMessage); m_ZipObj.ReceiveServiceMessage += new ZipDLLServiceMessageEventHandler(zipObj_ReceiveServiceMessage); btnStop.Enabled = true; //Zip the files int ret = m_ZipObj.ZipFiles(); //Examine the return code MessageBox.Show("Done. Ret: " + ret.ToString()); }