太棒了!
我正在对一个报告脚本,运行一系列的报告(pdf)上的按钮点击。报告是在web服务器上创建的,然后我希望用户可以选择下载文件。我已经写好了从服务器下载一个文件的脚本。但是我不确定如何下载多个文件?(可能会有50个左右)
在我运行一个报告之后,我将用户重定向到一个http处理程序脚本。
Response.Redirect("Download.ashx?ReportName=" + "WeeklySummary.pdf");
public class Download : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
StringBuilder sbSavePath = new StringBuilder();
sbSavePath.Append(DateTime.Now.Day);
sbSavePath.Append("-");
sbSavePath.Append(DateTime.Now.Month);
sbSavePath.Append("-");
sbSavePath.Append(DateTime.Now.Year);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpResponse objResponce = context.Response;
String test = HttpContext.Current.Request.QueryString["ReportName"];
HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; filename=" + test);
objResponce.WriteFile(context.Server.MapPath(@"Reports\" + sbSavePath + @"\" + test));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
}
public bool IsReusable { get { return false; } }
}提前感谢,如果你还想看我的剧本,请让我知道。
发布于 2010-10-20 21:56:26
我马上看到的两个选项是一个显而易见的选项,那就是简单地重复调用HTTP处理程序。另一种方法是在服务器上对它们进行压缩,然后通过网络发送一个压缩文件。您可以使用内置的GZipStream类来完成此任务。
此外,您还需要在处理程序中添加一些代码,以便在这些临时文件下载后对其进行清理。
https://stackoverflow.com/questions/3978446
复制相似问题