I'm having trouble wrapping my head around how to do this.
I have a DataTable being returned via stored procedure. I'm then going through it and creating a delimited file based off of the information returned.
I've made it here without any issues.
My problem is taking my StringBuilder object and creating a CSV file with it and then sending it to the user to download. I can't create a temporary file on the server due to permissions so I'm trying to do this all in memory.
I'm thinking I need to do something with a MemoryStream to create the "file" and then serving it up with Response but I'm not sure what steps to take.
content-disposition, to tell the browser that the response is a file), write the file (or the string, rather) to the output, and close the output. Good luck - David 2012-04-04 01:17
Response.Clear(); Response.ContentType = "application/CSV"; Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + ".csv\""); Response.Write(csvBuilder.ToString()); Response.End();
I'm pretty sure that this answer will get you on the right track.
Make sure you set the contentType to the appropriate values for your file.
response.ContentType = "text/plain";