Method code
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 ("~/1.txt"));
File. ADD (Server.MapPath ("~/1.txt"));
File. ADD (Server.MapPath ("~/1.txt"));
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 ();
Create a new NAMETRANSFOM class
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
ASP. NET multiple txt compression export download