Zipping Functionality : Automation Tools

Zipping Functionality

Ranorex Spy, Recorder, and Studio.

Zipping Functionality

Postby Praveen597 » Wed Dec 21, 2011 9:22 am

Hi All,

I need to add some files to the folder and zip that folder and attach the same to the mail. For this I am using following code but could able to zip the required folder.

ZipFile zip = new ZipFile();
for(int i=0;i<attachments.Length-1 ; i++)
{
System.IO.FileInfo f = new System.IO.FileInfo(attachments[i]);
zip.AddFile(attachments[i]);
}
zipfile = "myfolderpath is given here";
zip.Save(zipfile);

The result what I am getting is, I am able to add files to the specified path but the folder is not getting zipped.

Regards,
Praveen
Praveen597
 
Posts: 24
Joined: Sat Aug 27, 2011 10:41 am

Re: Zipping Functionality

Postby sdaly » Wed Dec 21, 2011 10:05 am

This is my method for zipping, its similar and works fine...

Code: Select all
public static void CreateZip(string zipName, params string[] filePathsToZip){
         using (ZipFile zip = new ZipFile())
         {
            foreach (string file in filePathsToZip) {
               if(File.Exists(file)){
                  zip.AddFile(file);
               }
            }
            zip.Save(zipName);
         }
      }
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland


Return to Automation Tools

Who is online

Users browsing this forum: No registered users and 0 guests

cron