I have a StringBuilder object which I have built with comma seperated values, which I would like to save as a .csv file.
I know how to stream the data as CSV, but how can I physically save the data as a .csv file, on the server?
Currently I stream the CSV like the following, where sb is StringBuilder:
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=List.csv")
Response.ContentType = "text/csv"
Response.Write(sb.ToString)
Response.End()
I assume you already know how to create csv, so check this question that shows how to save stream to file. As you’re using ASP.NET just make sure you have the appropriate permissions to modify.
Conclusion
As you want to make the download available to user(instead of save it in the server) and csv is basically a text file check out this