我想在一个button click
下载多个pdf文件。我使用的是开源dll," Ionic.Zip.Reduced.dll"。
所有代码都会运行而不显示任何错误或异常。通过使用Response.End()
,我在firefox的firebug窗口中得到了响应,但是当我在我的应用程序中使用它时会引发异常并且不显示任何下载对话框。所以,我把它改为HttpContext.Current.ApplicationInstance.CompleteRequest();
。现在异常消失了,但我没有得到任何响应和对话窗口下载。当我调试时,我发现了类似的东西:
ClientDisconnectedToken =' context.Response.ClientDisconnectedToken' 抛出了类型&System; System.PlatformNotSupportedException' :base {System.NotSupportedException} = {"此操作需要IIS 在集成管道模式下运行的7.5或更高版本。"}
这里真正的问题是,我可以使用相同的代码为新项目下载zip文件。
请帮我解决这个问题。这是我的代码:
System.Web.HttpContext context = System.Web.HttpContext.Current;
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("PDFs");
foreach (string item in FilePaths)
{
zip.AddFile(item.ToString(), "/PDFs/");
}
context.Response.Clear();
context.Response.BufferOutput = false;
context.Response.ClearHeaders();
context.Response.ClearContent();
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd- HHmmss"));
context.Response.ContentType = "Application/zip";
context.Response.AppendHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
context.Response.Flush();
context.Response.SuppressContent = true;
context.ApplicationInstance.CompleteRequest();
//Response.End();
}