C # Compressed package file download
public class MyNameTransfom:ICSharpCode.SharpZipLib.Core.INameTransform
{
#region Inametransform Members
public string Transformdirectory (string name)
{
return null;
}
public string TransformFile (string name)
{
return Path.getfilename (name);
}
#endregion
}
public partial class Default1:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Zipfilebycode ();
}
<summary>
Compress packaged Files
</summary>
public void Zipfilebycode ()
{
MemoryStream ms = new MemoryStream ();
byte[] buffer = NULL;
using (ZipFile file = Zipfile.create (ms))
{
File. BeginUpdate ();
File. Nametransform = new Mynametransfom ();//Through this name formatter, you can do some processing of the file name inside. By default, the relevant folder is created automatically based on the path of the file in the zip.
File. ADD (Server.MapPath ("/content/images/img01.jpg"));
File. ADD (Server.MapPath ("/content/images/img02.jpg"));
File.commitupdate ();
Buffer = new Byte[ms. Length];
Ms. Position = 0;
Ms. Read (buffer, 0, buffer. Length);
}
Response.AddHeader ("Content-disposition", "Attachment;filename=test.zip");
Response.BinaryWrite (buffer);
Response.Flush ();
Response.End ();
}
}
Required DLLs Download: Http://files.cnblogs.com/wangbogo/ICSharpCode.SharpZipLib.rar
C # Compressed package file download