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

下载txt文件,内容最前面多了一个样式引用的代码
C# code

                string fileName = filename;
                string filePath = Server.MapPath(ResolveUrl("~/DataBackUp/")) + filename;//路径
                FileStream fs = new FileStream(filePath, FileMode.Open);
                byte[] bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" +fileName);
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();


用这段代码来下载txt文件,内容的最前面,都会被加个
<link href="/App_Themes-green/skin/mystyle.css" rel="stylesheet" type="text/css" />
这个是我页面引用样式文件的代码。求指教。

------解决方案--------------------
加上Response.Clear()

 Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" +fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
------解决方案--------------------
顶起楼上大哥