Zipping Functionality

Ranorex Studio, Spy, Recorder, and Driver.
Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Zipping Functionality

Post by Praveen597 » Wed Dec 21, 2011 8: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);
zip.AddFile(attachments);
}
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

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Zipping Functionality

Post by sdaly » Wed Dec 21, 2011 9: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);
			}
		}