public class MyNameTransfom : ICSharpCode.SharpZipLib.Core.INameTransform
{
#region INameTransform 成员
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>
/// 压缩打包文件
/// </summary>
public void ZipFileByCode()
{
MemoryStream ms = new MemoryStream();
byte[] buffer = null;
using (ZipFile file = ZipFile.Create(ms))
{
file.BeginUpdate();
file.NameTransform = new MyNameTransfom();//名称格式化器
file.Add(Server.MapPath("/images/A类中医药适宜技术职业化培训证书1.jpg"));
file.Add(Server.MapPath("/images/A类中医药适宜技术职业化培训证书2.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();
}
{
#region INameTransform 成员
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>
/// 压缩打包文件
/// </summary>
public void ZipFileByCode()
{
MemoryStream ms = new MemoryStream();
byte[] buffer = null;
using (ZipFile file = ZipFile.Create(ms))
{
file.BeginUpdate();
file.NameTransform = new MyNameTransfom();//名称格式化器
file.Add(Server.MapPath("/images/A类中医药适宜技术职业化培训证书1.jpg"));
file.Add(Server.MapPath("/images/A类中医药适宜技术职业化培训证书2.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();
}
}