日期:2014-05-17  浏览次数:20483 次

附件下载的时候txt格式文件下载问题
txt格式的附件下载,变成了下载当前网页。这是怎么回事?
------最佳解决方案--------------------

     protected void Button3_Click(object sender, EventArgs e)
        {
            string fileName = "asd.txt";//客户端保存的文件名
            string filePath = "E://aaa.txt"; //Server.MapPath("DownLoad/aaa.txt");//路径
            FileInfo fileInfo = new FileInfo(filePath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            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.End();
        }



------其他解决方案--------------------
没碰过。直接右键另存呢?或者换个浏览器直接打开路径看看。
------其他解决方案--------------------
Chrome下载没问题,IE下载就有问题了。我把代码贴出来。
  FileStream fs = null;
                   try
                   {
                       String fileName = ViewState["Attchment"].ToString();
                       String filePath = Server.MapPath(@"~/UpLoad/Attchment/" + fileName);
                       //以字符流的形式下载
                       fs = new FileStream(filePath, FileMode.Open);
                       byte[] bytes = new byte[(int)fs.Length];
                       fs.Read(bytes, 0, bytes.Length);
      &nbs