Implementation Process
1) first reference 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 is compressed and downloaded
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: accounts and passwords at all levels of hohisoft.com ";
DlZipDir (userPath, "hohisoft.com service account ");
}
# Endregion