C#中有这样这一段代码, 
Response.Clear(); 
Response.ContentType   =   "application/octet-stream   "; 
Response.AddHeader( "Content-Disposition ", "attachment;   filename=\ " "+filename+ "\ " "); 
Response.Flush(); 
Response.WriteFile( "文件名 "); 
这段用于下载一个文件, 
同时我想在这段这后在重新刷新本页(因为要显示记录的原因), 
应该如何   正确的做?谢谢

解决方案 »

  1.   

                string filePath = Server.MapPath(FilePath);//路径            FileInfo fileInfo = new System.IO.FileInfo(filePath);            string s = filePath;
                string sub = s.Substring(s.LastIndexOf("\\") + 1, s.Length - s.LastIndexOf("\\") - 1);            Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(sub));
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.AddHeader("Content-Transfer-Encoding", "binary");
                Response.ContentType = "application/octet-stream";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                Response.WriteFile(fileInfo.FullName);
                Response.Flush();
                Response.Write("<script>alert('下载成功!');location='login.aspx';</script>");
                Response.End();
      

  2.   

    我要实现的功能就是,我上传了很多文件,然后我用一个DATAlist显示给别人看,
    DATAlist表头
    文件名   发布时间   是否下载   发布人   下载下载列,是一列按钮,就是用户想下载这个文件,就点按钮,然后下载完后,就将是否下载这个栏显示已下载,下载的记录是存在数据库中的
      

  3.   

    Response.End();这个不要,后面加Response.Redirect("");
      

  4.   

      Response.End();代表本次请求已经完成,之后你再写东西也不会反应到客户端,在  Response.End();之前去做你要做的处理
      

  5.   

     Response.Write("<script>alert('下载成功!');location='login.aspx';</script>");这不是在response.end()之前吗
      

  6.   

    在Response.End();之前向页面注册段脚本刷页面就行了
      

  7.   

    Response.End();这句话已注释掉了,Response.Write("<script>alert('下载成功!');location='login.aspx';</script>");
    这句,有执行,但是没有效果,我点浏览器的刷新后,内容不同,不知楼上明白我的意思了吗
      

  8.   

    location='login.aspx';换成window.location='login.aspx'试一下,
      

  9.   

    window.location.href='login.aspx';另外你要在Page_Load里自己写更新的逻辑。一个简单的办法是,把上句改成:window.location.href='login.aspx?downloadedfilename=' + filename;然后Page_Load里判断if (!String.IsNullOrEmpty(Request.QueryString["downloadedfilename"]))  则更新相应的区域