Wednesday, April 1, 2009

How to create a text file on the fly, let user download it in ASP.NET

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
sw.WriteLine("Name list");
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("content-disposition", "attachment;filename=teamlist.txt");
Response.Flush();
Response.Write(sb);
Response.End();

No comments:

Post a Comment