日期:2014-05-18  浏览次数:20933 次

asp.net做下载时下载下来的总是aspx页面
现在项目中用到这个功能,弄了一天也没弄好,我的代码如下:
  string Txt = friendBll.outFriend(userid, groupid);//获取文件内容
  fileName = groupBll.getFile(groupid).ToString();//文件名称
  fileName += DateTime.Now.ToShortDateString();

  string strFileName = HttpUtility.UrlEncode(fileName) + ".txt"; //文件名
  Response.Clear();
  Response.BufferOutput = false;
  Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
  Response.ContentType = "text/html";
  Response.AddHeader("Content-Disposition", string.Format("attachment;FileName= {0}",strFileName));
  byte[] bytes = Encoding.GetEncoding("UTF-8").GetBytes(Txt);
  Response.BinaryWrite(bytes); //文件流
  Response.Flush();
  Response.Close();
  Response.End();

------解决方案--------------------
asp.net上传下载大全