zip.save(); Can we do something in the method to automate the name of newly created zipfile

Jun 17, 2010 at 10:57 PM

Hi, I have been using the Ionic.zip namespace for the zipping program. But I have seen that we have to provide the name of the .zip file in C# program everytime and if the user has to zip many files he cannot go the sourcecode and change the program line everytime so I copied the sourcepath to a variable & then sourcepath/destddir should be given as input to "zip.save();" method so the new zipfile is named with the same name and the path would remain same as the directory from which it has been taken from.

public void button2_Click(object sender, EventArgs e) {

        String sourcepath = System.IO.Path.GetFullPath(openFileDialog1.FileName);
       
MessageBox.Show(sourcepath);
       
String destdir = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
       
MessageBox.Show(destdir);
       
try
       
{
           
using (ZipFile zip = new ZipFile())
           
{

               zip
.AddFile(sourcepath);

               zip
.Save(@"d:\todayTest2\myplate.zip");// Can I write this as zip.Save(sourcepath+ .zip); ??

             
}
            label1
.Text = "zipped";
}

I need to know the exact syntax of zip.save() method and Is it possible to give a variable as input to that method for saving a zip file. Thanks!

 

Coordinator
Jun 17, 2010 at 10:59 PM

The syntax for the Zip.Save() method is shown in the documentation;  http://cheeso.members.winisp.net/DotNetZipHelp/frames.htm

yes, you can pass a variable to that method.