代码之家  ›  专栏  ›  技术社区  ›  cnd

无法从Internet Explorer上的Web应用程序发送文件

  •  1
  • cnd  · 技术社区  · 16 年前

    错误是这样的: alt text

    无法从192.168.0.172加载Items.aspx

    代码:

       HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Charset = System.Text.Encoding.Unicode.EncodingName;
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
        HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.AddHeader(
             "content-disposition", string.Format(
                "attachment; filename={0}",fileName));
    

            table.RenderControl(htw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();
    

    此文件的问题仅适用于Internet Explorer(适用于opera/firefox…)

    所以它适用于HTML,没有

    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   tpeczek Joshua H    16 年前

    试着这样做:

    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);     
    HttpContext.Current.Response.Charset = System.Text.Encoding.Unicode.EncodingName;     
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
    HttpContext.Current.Response.AddHeader("Content-Type", "application/ms-excel");
    HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", outputFileName));
    HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
    ...
    table.RenderControl(htw);       
    HttpContext.Current.Response.Write(sw.ToString());
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();