Implementation process
1) first cite ICSharpCode.SharpZipLib.dll;
2). cs file introduced into
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 (hohisoft.com) All levels of accounts and passwords";
Dlzipdir (UserPath, "Huahai Training (hohisoft.com) service account");
}
#endregion