KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to write to a text file in memory and then download that file without saving the file to the hard disk. I'm using the StringWriter to write the contents: StringWriter oStringWriter = new StringWriter(); oStringWriter.Write("This is the content"); How do I then download this file? EDIT: It was combination of answers which gave me my solution. Here it is: StringWriter oStringWriter = new StringWriter(); oStringWriter.WriteLine("Line 1"); Response.ContentType = "text/plain"; Response.AddHeader("content-disposition", "attachment;filename=" + string.Format("members-{0}.csv",string.Format("{0:ddMMyyyy}",DateTime.Today))); Response.Clear(); using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { writer.Write(oStringWriter.ToString()); } Response.End();
Tags (comma-separated)
Save Edits
Cancel