Friday, December 3, 2010

Zipping a folder which contains multiple files using Ionic.Zip.dll library


              String ReadmeText = string.Format("This file was created automatically by..... application on," + DateTime.Now.ToString("yyyy-MMM-dd--HH:mm:ss"), DownloadfileName, Environment.NewLine);
                StreamWriter sw = File.CreateText(Server.MapPath("~//zipfolder//Readme.txt"));
                sw.WriteLine(ReadmeText);
                sw.Close();
                string path = Server.MapPath("~//zipfolder//MyZipFile");
                using (ZipFile zip = new ZipFile())
                 {
                     zip.AddFile(Server.MapPath("zipfolder//Readme.txt"),"");
                     zip.AddFile(Server.MapPath("xmlfolder//ss.xml"),"");
                     zip.Save(Server.MapPath("~//zipfolder//MyZipFile.zip"));
                  }

For to Download a file

        Response.Clear();
        string archiveName = String.Format("xml-{0}.zip", ".zip");
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "filename=MyZipFile" + archiveName);
        Response.TransmitFile(Server.MapPath("~\\zipfolder\\MyZipFile.zip"));
        Response.End();