ASP.Net实现实时压缩的方法多种多样了。比较多都是使用开源的SharpZipLib
下载地址是:http://prdownloads.sourceforge.net/sharpdevelop/084SharpZipLib.zip?use_mirror=jaist
结构很明晰
ICSharpCode.SharpZipLib.Tar.*
Tar implementation
ICSharpCode.SharpZipLib.GZip.*
Gzip implementation
ICSharpCode.SharpZipLib.BZip2.*
Bzip2 implementation
ICSharpCode.SharpZipLib.Zip
Zip implementation
ICSharpCode.SharpZipLib.Zip.Compression.Streams
Inflater/Deflater streams
|
网络上有不少代码范例:
〈%@ Import namespace=“ICSharpCode.SharpZipLib.Zip“ %〉 〈%@ Import Namespace=“System.IO“ %〉 〈script language=“c#“ runat=“server“〉 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){ |
当然如果觉得这个比较复杂还有更简单的NZipLib.dll 可以用
http://www.aspheute.com/english/20011115.asp
这个是比较老牌的