web 导出 csv
2015-06-09 21:34
309 查看
public void ProcessRequest(HttpContext context)
{
//DownloadFile("教程.csv", "a.csv");
context.Response.Charset = "UTF-8";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("测试.csv"));
context.Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });
context.Response.Write("编号,姓名\n1,邸萌");
context.Response.Flush();
context.Response.End();
}
#region 提供文件下载的方法【只限于服务器端已经存在的文件】
/// <summary>
/// 提供文件下载的方法【只限于服务器端已经存在的文件】
/// </summary>
/// <param name="fileName">一定要有后缀名。下载保存时文件的名称,可以与实际文件名称不相同,可以是中文</param>
/// <param name="filePath">要下载文件的虚拟路径</param>
public void DownloadFile(string fileName, string filePath)
{
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.WriteFile(filePath);
}
#endregion
{
//DownloadFile("教程.csv", "a.csv");
context.Response.Charset = "UTF-8";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("测试.csv"));
context.Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });
context.Response.Write("编号,姓名\n1,邸萌");
context.Response.Flush();
context.Response.End();
}
#region 提供文件下载的方法【只限于服务器端已经存在的文件】
/// <summary>
/// 提供文件下载的方法【只限于服务器端已经存在的文件】
/// </summary>
/// <param name="fileName">一定要有后缀名。下载保存时文件的名称,可以与实际文件名称不相同,可以是中文</param>
/// <param name="filePath">要下载文件的虚拟路径</param>
public void DownloadFile(string fileName, string filePath)
{
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.WriteFile(filePath);
}
#endregion
相关文章推荐
- Java for LeetCode 219 Contains Duplicate II
- LazyCode 自己开源的一个类库
- POJ 3518
- null类型强转
- Visual Studio 2010/2013 UTF8编码调试时显示中文
- Java for LeetCode 218 The Skyline Problem【HARD】
- 黑马程序员——Java基础---IO流(字符流)
- Java for LeetCode 217 Contains Duplicate
- UVa1635 - Irrelevant Elements
- POJ2092
- 隐马尔科夫学习七(五)
- hdoj 3664 Permutation Counting 【递推 有点类似杨辉三角】
- go语言调用API实线分词
- 14443协议的一些小的问题集锦
- Solr in action学习笔记 第五章 Index
- C#语法糖之 session操作类 asp.net
- AtomicBoolean介绍与使
- 线程 进程 多线程的使用
- mongodb笔记之update
- Android 5.1部分apk的升级或缓存功能无效