生成文件并直接输出下载

string fileName = "";

fileName 
= DateTime.Now.ToFileTime() + ".csv";

MemoryStream memory 
= new MemoryStream();
StreamWriter writer 
= new StreamWriter(memory, System.Text.Encoding.GetEncoding("GB2312"));

string title = "内容";
writer.WriteLine(title);

writer.Flush();
          
Response.Clear();
Response.ClearHeaders();
Response.Buffer 
= true;
Response.ContentType 
= "application/csv";
Response.AddHeader(
"Content-Disposition""attachment;filename=" + fileName);
Response.BinaryWrite(memory.ToArray());

Response.End();
posted @ 2008-09-26 18:02  zzh  阅读(289)  评论(0编辑  收藏  举报