if (System.IO.File.Exists(Path))
        {
            string fileName = era.Ename;//客户端保存的文件名
            string filePath = Path;//路径            //以字符流的形式下载文件
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(long)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            JS("alert('\"文件不存在\"');", this.Page);
        }
这是我的下载代码,现在代码能完整的运行,bytes 数组的大小跟文件大小也一样,问题执行完之后浏览器的下载框没有出现,即没有进行下载操作,谁帮忙看看。

解决方案 »

  1.   

     string Path = Server.MapPath("test.doc");
            if (System.IO.File.Exists(Path))
            {
                string fileName ="test.doc";//客户端保存的文件名
                string filePath = Path;//路径            //以字符流的形式下载文件
                FileStream fs = new FileStream(filePath, FileMode.Open);
                byte[] bytes = new byte[(long)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                Response.ContentType = "application/octet-stream";
                //通知浏览器下载文件而不是打开
                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }
    测试了。。没问题啊。
      

  2.   

    问题找到了,不是浏览器的关系
    是.NET的那个ajax:AjaxPanel造成的
    移出这个标签就OK了
    坑爹啊