我正在尝试下载生成的pdf文件,我的代码如下:
public class GetPDF : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
PDFGenerator generatePDF = new PDFGenerator();
FileInfo file = generatePDF.GeneratePDFHtml();
if (file.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.AppendHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.TransmitFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
我已经尝试了很多来自网络的资源。
我没有休息,没有错误,它什么也没做。
任何帮助,将不胜感激
我不清楚您的问题,但如果成功生成文件,那么您想推送到客户端。我相信您正在使用aspx页面内的更新面板,并且必须向控件添加触发器以进行回发。
<触发器> <asp:PostBackTrigger ControlID =“ btnPrint” /> </ Triggers>
将此等效触发器添加到您的页面
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句