Chinaunix首页 | 论坛 | 博客
  • 博客访问: 628588
  • 博文数量: 87
  • 博客积分: 3399
  • 博客等级: 中校
  • 技术积分: 1422
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-17 21:20
文章分类

全部博文(87)

文章存档

2013年(1)

2012年(51)

2011年(33)

2010年(2)

分类: Web开发

2013-03-04 16:48:20

1 读取文件并输出到客户端

点击(此处)折叠或打开

  1. string fileURL="d://test.xls";
  2.         System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileURL);
  3.         Response.Clear();
  4.         Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
  5.         Response.AddHeader("content-length", fileInfo.Length.ToString());
  6.         Response.ContentType = "application/octet-stream";
  7.         Response.Charset = "gb2312";
  8.         Response.ContentEncoding = Encoding.UTF8;
  9.         Response.WriteFile(fileURL);
  10.         Response.Flush();
  11.         Response.End();

2 将流中的数据写入到文件


点击(此处)折叠或打开

  1. StringWriter sw = new StringWriter();
  2.              string str = "12t34t56thah";
  3.              sw.WriteLine(str);
  4.              输出到Excel
  5.              Response.Clear();
  6.              Response.AddHeader("Content-disposition", "attachment;filename="+filename+".xls");
  7.              //Response.ContentEncoding = Encoding.GetEncoding("gb2312");
  8.              Response.ContentEncoding = Encoding.UTF8;
  9.              Response.ContentType = "application/ms-excel";
  10.              Response.Charset = "gb2312";
  11.              Response.Write(sw.ToString());
  12.              sw.Close();
  13.              Response.Flush();
  14.              Response.End();

阅读(8079) | 评论(0) | 转发(0) |
2

上一篇:gedit 乱码问题

下一篇:没有了

给主人留下些什么吧!~~