代码之家  ›  专栏  ›  技术社区  ›  Dimi Takis

文件下载对话框IE7消失

  •  2
  • Dimi Takis  · 技术社区  · 16 年前

    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.Clear();
    response.AddHeader("Content-Disposition", "attachment;filename=Contacts.xls");
    response.ContentType = "application/octet-stream";
    
    System.Text.UnicodeEncoding Encoding = new System.Text.UnicodeEncoding();
    
    byte[] unicodeBytes = {255,254};
    int length = 2 + Encoding.GetByteCount(_exportContent); // _exportContent is string.
    response.AddHeader("Content-Length", length.ToString());
    response.OutputStream.Write(unicodeBytes, 0, 2);
    unicodeBytes = Encoding.GetBytes(_exportContent);
    response.OutputStream.Write(unicodeBytes, 2, unicodeBytes.Length);
    response.End();
    

    我正在用js(window.open())打开aspx页面,并在页面_Load()中执行上述代码。

    奇怪的是,窗口会弹出,试图加载/显示文件对话框,然后你会听到弹出窗口被阻止的声音(尽管弹出窗口阻止程序已停用!)。

    额外资料:
    -同样的代码适用于FW2.0 -Firefox在显示文件对话框方面没有问题。

    我很好奇是否有其他人遇到过同样的问题,并能提供一个在IE7中工作的解决方案。

    干杯
    迪米

    5 回复  |  直到 16 年前
        1
  •  2
  •   scunliffe    16 年前

    添加一个标题来告诉IE 明确地

        2
  •  2
  •   R2D2 R2D2    16 年前

    我也有同样的问题,花了一个小时完全沮丧。和往常一样,微软IE浏览器是所有头痛的根源。在其他浏览器中一切都正常。解决方案很简单: 用户必须通过转到来调整IE7设置 “工具”>'Internet选项“>”“安全”选项卡>对于“Internet”和/或“本地intranet”,通过单击“自定义级别…”按钮调整安全设置

    这为我的用户修复了它。

    希望有帮助。

        3
  •  1
  •   Chipie    14 年前

    在我们的内联网上有这个问题,自动提示下载对我来说不起作用(已经被选中),但这确实。。。

    工具->互联网选项

    单击高级

    类型http://your.url.com 然后单击添加

    单击关闭->好的->好啊

        4
  •  0
  •   Andrew E kirin Andrew E kirin    16 年前

    我仍然无法使对话框不消失。当应用程序访问[webmethod]以收集信息并传递到尝试将结果下载到excel的页面时,就会发生这种情况。

                Response.Clear();
    
                Response.ClearHeaders();
                Response.ClearContent();
    
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileNameToUse + "\"");
                 Response.CacheControl = "Public";
    
                Response.Write(output);
                Response.Flush();
                Response.Close();
    

        5
  •  0
  •   dhiru dhiru    16 年前

    要测试安全性是否导致此问题,请将目标设置为_self。IE顶部的警告栏应出现。 如果这是原因,检查IE安全。特别是下载提示部分。

    推荐文章