生成文件并直接输出下载
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();
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();