文件流下载后缀为doc的文档没有问题, 下载txt后缀的,在文档里面会自动拼接本页的html代码, 求解决方案。
//以字符流的形式下载文件
FileStream fsDownLoad = new FileStream(ZHHsavePath, FileMode.Open);
byte[] bytes = new byte[(int)fsDownLoad.Length];
fsDownLoad.Read(bytes, 0, bytes.Length);
fsDownLoad.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("【转换后】" + name + ".txt", System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Context.ApplicationInstance.CompleteRequest();