日期:2014-05-18  浏览次数:20415 次

关于XP系统下Response.write打开附件不能关闭IE问题
FileInfo fi = new FileInfo(FilePath);
  Response.Clear();
  Response.ClearHeaders();
  Response.Buffer = false;
  Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(FileName), System.Text.Encoding.UTF8));
  Response.AppendHeader("Content-Length", fi.Length.ToString());
  Response.ContentType = "application/octet-stream";
  Response.WriteFile(FilePath);
  Response.Flush();
  Response.End();
以上代码是关于附件下载的,现在的问题是在windows server 2003下一切正常,但是在XP下就出现一个空的IE要手动才能关掉。不知道是什么原因。请各位提点一下。

------解决方案--------------------
FileInfo fi = new FileInfo(FilePath); 
Response.Clear(); 
Response.ClearHeaders(); 
Response.Buffer = false; 
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(FileName), System.Text.Encoding.UTF8)); 
Response.AppendHeader("Content-Length", fi.Length.ToString()); 
Response.ContentType = "application/octet-stream"; 
Response.WriteFile(FilePath); 
Response.Flush(); 
Response.End(); 

Response.write("<script language=javascript>opener = null;window.close();</script>");

你在后面再加上一段代码让页面自己关掉
------解决方案--------------------
我有时下载有些东西都是这样~~要手动才能关闭~~~
------解决方案--------------------
这个学习下!帮顶个..................
UP.....
------解决方案--------------------
XP 系统自身的问题。
------解决方案--------------------
FileInfo fi = new FileInfo(FilePath);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(FileName), System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(FilePath);
Response.Flush();
         
         Response.write(" <script language=javascript >window.opener = null;window.close(); </script >");
Response.End();

 
------解决方案--------------------
Response.Buffer = true; 
看看
------解决方案--------------------
死了这条心吧,这种写法是没有办法关闭的。用户自己关闭也没什么,很多网站都这样做
------解决方案--------------------
可能是客户端IE设置问题,是在所有XP系统都不好使吗?
------解决方案--------------------
我的就是XP啊。没有出现空白的页面。

string FilePath= "D:/Program Files/LeapFTP/20081522632.rar";
string FileName = "20081522632.rar";
FileInfo fi = new FileInfo(FilePath); 
Response.Clear(); 
Response.ClearHeaders(); 
Response.Buffer = false;