Steps
1) First quote ICSharpCode.SharpZipLib.dll;
2). cs File Introduction
Using System.IO;
Using System.Text;
Using ICSharpCode.SharpZipLib.Checksums;
Using ICSharpCode.SharpZipLib.Zip;
Using ICSharpCode.SharpZipLib.GZip;
3) Code
#region The following code to compress and download the code
Zipoutputstream Zos = null;
String strbasedir = "";
void Dlzipdir (String strpath, String strfilename)
{
MemoryStream ms = NULL;
Response.ContentType = "Application/octet-stream";
strFileName = Httputility.urlencode (strFileName) . Replace (' + ', ' ');
Response.AddHeader ("Content-disposition", " attachment; filename= "+ strFileName +". zip ");
ms = new MemoryStream ();
Zos = new Zipoutputstream (MS);
strbasedir = strpath + "";
Addzipentry (sTRBASEDIR);
Zos. Finish ();
Zos. Close ();
response.clear ();
Response.BinaryWrite (Ms. ToArray ());
Response.End ();
}
void Addzipentry (string pathstr)
{
DirectoryInfo di = new DirectoryInfo (PATHSTR);
foreach (DirectoryInfo item in DI. GetDirectories ())
{
addzipentry (item. FullName);
}
foreach (FileInfo item in DI. GetFiles ())
{
FileStream fs = File.openread (item. FullName);
byte[]Buffer = new Byte[fs. Length];
FS. Read (buffer, 0, buffer.) Length);
String strentryname = Item. Fullname.replace (Strbasedir, "");
ZipEntry entry = new ZipEntry (Strentryname);
Zos. Putnextentry (entry);
Zos. Write (buffer, 0, buffer.) Length);
FS. Close ();
}
}
PRotected void Button2_Click (object sender, EventArgs e)
{
String UserPath = "D: Huahai Training (qqview.com) All levels of accounts and passwords";
Dlzipdir (UserPath, "Huahai Training (qqview.com) service account");
}
#endregion