[英]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.