首页 > Web开发 > 详细

aspx导出文件

时间:2014-04-13 00:43:02      阅读:481      评论:0      收藏:0      [点我收藏+]

System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// reptype.RenderControl(htw);//reptype为要导出的对象,当前是reptype,如果是DataGrid,DataList等都可以
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Response.ContentType";//Response.ContentType是输出流的 HTTP MIME 类型
//Response.ContentType --- word文件
//application/vnd.ms-excel --- excel文件
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("试卷", System.Text.Encoding.UTF8) + ".doc");
//attachment --- 作为附件下载
//inline --- 在线打开
//filename如果是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)进行进行编码,以解决文件名乱码的问题

Response.Write("aa"+"\n"+"sd");
Response.Flush();
Response.Close();

aspx导出文件,布布扣,bubuko.com

aspx导出文件

原文:http://www.cnblogs.com/kexb/p/3660401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!