Zip file & Folder Asp.Net ,C#

 Zip in Asp.Net, C#

string sPath = Server.MapPath("~") + "DownloadFolder";

string sPath = Server.MapPath("~") + "DownloadFolder";

string zipFullPath = Server.MapPath("~") + "DocumentFolder.zip";

ZipOutputStream zipOut = new ZipOutputStream(File.Create(zipFullPath));

foreach (string fName in Directory.GetFiles(sPath))

{

FileInfo fi =
new FileInfo(fName);

ZipEntry entry = new ZipEntry(fi.Name);

FileStream sReader = File.OpenRead(fName);byte[] buff = new byte[Convert.ToInt32(sReader.Length)];

sReader.Read(buff, 0, (int)sReader.Length);

entry.DateTime = fi.LastWriteTime;

entry.Size = sReader.Length;

sReader.Close();

zipOut.PutNextEntry(entry);

zipOut.Write(buff, 0, buff.Length);

}

zipOut.Finish();

zipOut.Close();

Dont forget to import the fully qualified namespace using ICSharpCode.SharpZipLib.Zip ;)

By: VidyaGyan