这是从方法直接复制的,
参数 fileType是文件格式
参数filedName是写出后文件的文件名。
参数suffix是写出后文件的文件后缀名。
Response.Clear(); //清空 缓冲区的所有输出数据
Response.Charset = "utf-8";//设置输出输出流字符类型
Response.ContentType = fileType;设置输出流的 file MIME类型
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName) + suffix);//将HTTP 头添加到输出流,“+”以前是固定的 字符串连接是为了写文件名和文件后缀名
Response.Write("<html><head><Meta http-equiv=/"Content-Type/"content=/"text/html;charset=utf-8/"></head><body>");
Response.Write("<h1>"+article.Title+"</h1><p/>"+article.Context);
Response.Write("</body></html>");
//文件内容
Response.End();
//关闭
当导出的文件为 文本格式时 Response.Write(" ")中就不必写入HTML代码,如果写入了,文本内容会出现 HTML
Response.ContentType ="application/ms-excel";是excel
Response.ContentType ="Content-Disposition";是word