我实现的下载功能是这样写的
string filepath="";
filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
System.IO.FileInfo myFile = new System.IO.FileInfo(filepath); 
filename=this.Request["ImgePath"];
filename=filename.Substring(filename.Length-3,3);
if (filename=="jpg")
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name)); 
}
else
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif")); 
}
Response.AddHeader("Content-Length", myFile.Length.ToString()); 
this.Response.ContentType="application/octet-stream";
Response.WriteFile(myFile.FullName);
this.Response.End();
能实现下载~但下载完后下载页面一直留在那里~无法自动关闭~我试着在最后加了window.close()但还是不行~而且加了之后流有问题~希望高手指点一下

解决方案 »

  1.   

    修改成这样你试试:
    string filepath="";
    filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
    System.IO.FileInfo myFile = new System.IO.FileInfo(filepath); 
    filename=this.Request["ImgePath"];
    filename=filename.Substring(filename.Length-3,3);
    if (filename=="jpg")
    {
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name)); 
    }
    else
    {
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif")); 
    }
    Response.AddHeader("Content-Length", myFile.Length.ToString()); 
    this.Response.ContentType="application/octet-stream";
    Response.WriteFile(myFile.FullName);
    Response.flush();
    this.Response.End();
      

  2.   

    如果你是打开新窗口的话
    如果是window.open()的话,你可以试着window.close();
    或window.openner=null;window.close();
      

  3.   

    我试试~我是打开的新窗口~我也试过加window.close();但好象不行~我再试试~
      

  4.   

    Response.flush();要加什么命名空间吗?抱错了
      

  5.   

    不会吧!
    我的源代码给你
    System.IO.FileInfo file = new System.IO.FileInfo("F:\\mp3\\mp3\\别哭我最爱的人.mp3");
    Response.Clear();
    Response.ClearHeaders();
    Response.Buffer = false;
    Response.Charset="GB2312";
    Response.ContentEncoding=System.Text.Encoding.UTF8;
    Response.ContentType = "application/octet-stream";

    Response.AddHeader("Content-Disposition", "attachment; filename="+Server.UrlEncode("别哭我最爱的人.mp3"));
    Response.AddHeader("Content-Length", file.Length.ToString());     
    Response.WriteFile(file.FullName);
    Response.Flush();
    Response.End();
      

  6.   

    Response.Write("<script>window.close();</script>");
      

  7.   

    window.openner=null;window.close();
    这个方法我试过的不行啊~~555
      

  8.   

    Response.Write("<script>window.openner=null;window.close();</script>");
    放在
    Response.End();
    之前
      

  9.   

    我是这样写的啊
    string filepath="";
    filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
    System.IO.FileInfo myFile = new System.IO.FileInfo(filepath);
    filename=this.Request["ImgePath"];
    filename=filename.Substring(filename.Length-3,3);
    if (filename=="jpg")
    {
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name)); 
    }
    else
    {
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif")); 
    }
    Response.AddHeader("Content-Length", myFile.Length.ToString()); 
    this.Response.ContentType="application/octet-stream";
    Response.WriteFile(myFile.FullName);
    Response.Write("<script language=javascript>window.openner=null;window.close();</script>");
    this.Response.End();
      

  10.   

    Response.Write("<script language=javascript>window.openner=null;window.close();</script>");
    这样的方法肯定是不行的,不管你在什么时候写
      

  11.   

    新页面用框架,把下载文件的连接放在隐藏框架里,在大框架里延时一段时间,用window.close()关闭页面
      

  12.   

    你可以打开新页
    但不要加target="_blank"
    在本页跳转
    我相信上述我写的代码应该可以
      

  13.   

    建议下载页面不要用page,用一个类继承IHttpHandler
      

  14.   

    打开新页面就是window.open("download.aspx?&ISdown=T&ImgePath="+Form1.imgsl.options[i].value+"");
      

  15.   

    靠,csdn 自己就有这个玩意,试试在打开的窗口里写——<html>
    <head>
    <title>CSDN技术网摘 -- wz.csdn.net</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="StyleSheet" href="/main.css" type="text/css" media="screen"><script type="text/javascript">
    function closeIt() {
    self.close();
    }
    function doClose() {
    setTimeout("closeIt()", 2000);
    }
    </script>
    </head><body bgcolor="white" onLoad="doClose();">
    <table width="100%" height="75%" border="0" cellspacing="0" cellpadding="0">
    <tr><td valign="center">
    <center><table width="300" class="greenBox">
    <tr><th>成功啦!</th></tr>
    <tr><td align="center">
    <span class="success">网页成功保存.</span><br/><br/>
    <a href="/my" target="_blank">进入我的网摘管理</a>
    </td></tr>
    </table></center>
    </td></tr>
    </table>
    </body>
    </html>