简体   繁体   English

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

[英]Can't send file from Web Application on Internet Explorer

Error is something like that : 错误是这样的: 替代文字

Can't load Items.aspx from 192.168.0.172 无法从192.168.0.172加载Items.aspx

And a text is Can't open this web-site. 文字为“无法打开该网站”。 It can't be found. 找不到。 Try later 等会再试

code : 代码:

   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();

Trouble with this file is only for Internet Explorer (works on opera / firefox ... ) 此文件的问题仅适用于Internet Explorer(适用于Opera / firefox ...)

And so it works for HTML with no 因此,它适用于HTML

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

this string 这个字符串

How to avoid this error on IE ? 如何避免IE出现此错误?

Try like this: 尝试这样:

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Visual Studio Web性能测试记录器可以将文件从Internet Explorer保存到本地磁盘吗? - Can Microsoft Visual Studio Web Performance Test Recorder save file from the Internet Explorer to local disk? 尝试从Web应用程序访问报告服务时,Internet Explorer导致IIS 500错误 - Internet Explorer causes IIS 500 error when attempting to access reporting services from a Web Application 我如何发送文件以接收回值(适用于Internet Explorer 8-9)? - How I can send a file to receive a value back (that works for internet explorer 8-9)? 无法在Internet Explorer中看到图像 - Can't see images in internet explorer 将文件从Internet下载到ASP.NET MVC Web应用程序 - Downloading a file from internet to ASP.NET MVC web application 从 microsoft edge 而不是 internet explorer 中的 web 浏览器控件打开本地 html 文件 - open a local html file from web browser control in microsoft edge instead of internet explorer 使用 Microsoft Edge 将数据发送到网站(从 Internet Explorer 切换) - Send data to a website using Microsoft Edge (switching from Internet Explorer) 可以使用Firefox和Chrome从WCF服务下载文件,但不能从Edge和Internet Explorer 11下载文件 - Can download a file from WCF service using firefox and chrome but not Edge and Internet Explorer 11 无法读取流(StreamReader .net),从带有angular(1.5)$ http.post和json的Internet Explorer 10发送数据作为数据 - Stream can not be read (StreamReader .net), send from Internet Explorer 10 with angular (1.5) $http.post and json as data 从C#应用程序在Internet Explorer中添加按钮并复制内容 - Add button in Internet Explorer from C# application and copy content
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM