zoukankan      html  css  js  c++  java
  • UpdatePanel无法导出下载文件

    转自 http://www.cnblogs.com/vipsoft/p/3298299.html

    protected void Page_Load(object sender, EventArgs e) { ScriptManager sm = Page.Master.FindControl("ScriptManager1") as ScriptManager; if (sm != null) { foreach (GridViewRow item in gvInvoiceHistory.Rows) { LinkButton lbtnTemp = item.FindControl("btnInvoiceNumber") as LinkButton; if (lbtnTemp != null) { sm.RegisterPostBackControl(lbtnTemp); } } } } protected void btnInvoiceNumber_OnClick(object sender, EventArgs e) { LinkButton btnTemp = sender as LinkButton; if (btnTemp != null) { var path = ConfigurationManager.AppSettings["InvoicePdfPath"]; var fileName = btnTemp.Text.Trim() + ".pdf"; if (!FileHandler.DownLoadFile(path, fileName)) { var msg = GetLocalResourceObject("InvoiceIsNotAvailable").ToString(); ScriptManager.RegisterStartupScript(upMain, upMain.Page.GetType(), "DownLoadFile", string.Format("alert('{0}');", msg), true); //如果不存在就跳转,参见 http://www.cnblogs.com/vipsoft/p/3627683.html       //string url = "http://www.vipsoft.com.cn";       //ResponseRedirect.Redirect(Response, url, "_blank", "'toolbar=0,scrollbars=1,status=0,menubar=0,resizable=1,top=0,left=0,height=800,width=1000");} } } } //Updatepanel 会有异常 参考下面的链接查看下载方法 public static bool DownLoadFile(string path,string fileName) { bool result = false; string filePath = HttpContext.Current.Server.MapPath(path + fileName); if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary"); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); HttpContext.Current.Response.WriteFile(fileInfo.FullName); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); result = true; } return result; }
    复制代码

    ScriptManager1 放在 MasterPage中,查找 ScriptManager1 时,
    Page.Master.FindControl("ScriptManager1") as ScriptManager;

    FileHandler文件下载:http://www.cnblogs.com/vipsoft/p/3521958.html

    如果不存在就跳转,参见 http://www.cnblogs.com/vipsoft/p/3627683.html

  • 相关阅读:
    初识JAVA
    计算机语言发展史
    课时11:禁用、清理二级缓存,以及整合Ehcache缓存
    课时10:MyBatis一级缓存、二级缓存
    课时9::MyBatis整合Log4j、延迟加载
    课时7:动语态SQL、foreach、输入参数为类中的集合属性、集合、数组、动态数组
    课时6 输出参数为简单类型、对象类型、HashMap及resultMap使用
    课时5 入参为HashMap,以及mybatis调用存储过程CRUD
    课时4:l两种取值符号以及ParameterType为简单,对象,嵌套对象类型
    课时3:属性文件丶全局参数丶别名丶类型转换器丶resultMap
  • 原文地址:https://www.cnblogs.com/cpcpc/p/5606006.html
Copyright © 2011-2022 走看看