Dec 23, 2011, 7:49 PM
ext Button event Response file garbled,bu in the net button is good
protected void Button_DirectClick1(object sender, DirectEventArgs e)
{
using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))
{
//设置压缩密码,经测试设要设置置密码必须第一步设置,再添加文件或者文件夹后设置无效
// zip.Password = "MyTest";
//要压缩的文件夹
//zip.AddDirectory(Request.PhysicalApplicationPath);
//还可以再追加多个要压缩的文件夹或文件
//zip.AddFile(@"c:\1.txt");
zip.AddDirectory(Server.MapPath("Tool"));
//追加一个说明文档
zip.AddEntry("说明.txt", "说明内容", Encoding.GetEncoding("gb2312"));
MemoryStream ms = new MemoryStream();
zip.Save(ms);
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.zip", HttpUtility.UrlEncode("111111")));
Response.BinaryWrite(ms.ToArray());
ms.Close();
ms.Dispose();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))
{
//设置压缩密码,经测试设要设置置密码必须第一步设置,再添加文件或者文件夹后设置无效
// zip.Password = "MyTest";
//要压缩的文件夹
//zip.AddDirectory(Request.PhysicalApplicationPath);
//还可以再追加多个要压缩的文件夹或文件
//zip.AddFile(@"c:\1.txt");
zip.AddDirectory(Server.MapPath("Tool"));
//追加一个说明文档
zip.AddEntry("说明.txt", "说明内容", Encoding.GetEncoding("gb2312"));
MemoryStream ms = new MemoryStream();
zip.Save(ms);
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.zip", HttpUtility.UrlEncode("111111")));
Response.BinaryWrite(ms.ToArray());
ms.Close();
ms.Dispose();
}
}
Help me, thank you, welcome you to come to the Chinese guest
Last edited by Daniil; Dec 24, 2011 at 8:55 AM.
Reason: Please use [CODE] tags