You don't need to save the CSV file to disk especially if it is dynamically generated. You could directly write it to the response stream so that the user can download it:
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/csv";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.csv");
Response.Write("val1,val2,val3");
}
You could also write an http handler:
public class CsvHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.AppendHeader("Content-Disposition", "attachment; filename=foo.csv");
context.Response.ContentType = "text/csv";
context.Response.Write("val1,val2,val3");
}
public bool IsReusable
{
get { return true; }
}
}
which you would call like this: http://mysite.com/csvhandler.ashx