日期:2014-05-20  浏览次数:20399 次

下载文件后关闭窗体问题
求大侠帮忙看下,,如何才能在下载文件完后让窗体关闭.
下面是我的代码.放在a.aspx的Page_Load里面,,可是保存完文件还是不会关闭.
求教应该如何改呀?
我看过网上那篇下载文件关闭的文章   ,但用在这里还是不起用,,
在线等待,,测试通过马上结贴,,谢谢


string   AppPath   =   HttpContext.Current.Request.PhysicalApplicationPath;
string   ImageFolderPath   =   AppPath   +   "Public\\127933387836406250ball6.gif ";

FileStream   myFile   =   new   FileStream(ImageFolderPath,   FileMode.Open,   FileAccess.Read,   FileShare.ReadWrite);
BinaryReader   br   =   new   BinaryReader(myFile);
     context.Response.Buffer   =   false;
     context.Response.Clear();
context.Response.AddHeader( "Connection ",   "Keep-Alive ");
     context.Response.ContentType   =   "application/octet-stream ";
     context.Response.AddHeader( "Content-Disposition ", "attachment;filename= "   +   HttpUtility.UrlEncode( "无聊提.jpg "));
context.Response.AddHeader( "Content-Length ",   myFile.Length.ToString());

  while   (true)
{
//开辟缓冲区空间
byte[]   buffer   =   new   byte[1024];
//读取文件的数据
int   leng   =   myFile.Read(buffer,   0,   1024);
if   (leng   ==   0)//到文件尾,结束
break;
if   (leng   ==   1024)//读出的文件数据长度等于缓冲区长度,直接将缓冲区数据写入HttpUtility.UrlEncoding(filename.ToString   ())
context.Response.BinaryWrite(buffer);
else
{
//读出文件数据比缓冲区小,重新定义缓冲区大小,只用于读取文件的最后一个数据块Server.UrlEncode(fileName)
byte[]   b   =   new   byte[leng];
for   (int   i   =   0;   i   <   leng;   i++)
b[i]   =   buffer[i];
context.Response.BinaryWrite(b);
}
}
myFile.Close();//关闭下载文件

     context.Response.Flush();
     context.Response.End();

------解决方案--------------------
窗体关闭:Response.Write( " <script> window.close(); </script> ");
------解决方案--------------------
和浏览器的补订包有关,我在项目中也经历过这种情况,同样的代码在相同版本的不同补订包浏览器中执行的结果是不同的。
------解决方案--------------------
把context.Response.Flush();
     context.Response.End();这两句去掉再加上Response.Write( " <script> window.close(); </script> ");

------解决方案--------------------
UP