Add the Referece for the project - ionic.utils.zip.dll
Add the Namespace using Ionic.Utils.Zip;


String SourLocation = String.Empty;
String DestLocation = String.Empty;

protected void Page_Load(object sender, EventArgs e)
{
try
{
SourLocation = ConfigurationManager.AppSettings["SourceLocation"].ToString();
DestLocation = ConfigurationManager.AppSettings["TargetLocation"].ToString();
}
catch (Exception ex)
{ }
}

protected void btnCreate_Click(object sender, EventArgs e)
{
ZipFile oSourceZip = null;
try
{
oSourceZip = new ZipFile(ConfigurationManager.AppSettings["SourceZip"].ToString());

if (Directory.Exists(SourLocation))
{
if (Directory.GetDirectories(SourLocation).Length > 0)
{
foreach (String sDirectory in Directory.GetDirectories(SourLocation))
{
oSourceZip.AddDirectory(sDirectory, sDirectory.Substring(sDirectory.LastIndexOf("\\") + 1));
}
}
if (Directory.GetFiles(SourLocation).Length > 0)
{
foreach (String sfileName in Directory.GetFiles(SourLocation))
{
oSourceZip.AddFile(sfileName, "");
}
}
oSourceZip.Save();
}
}
catch (Exception ex){ }
}

Category : | Read More......