Tuesday, August 26, 2008

Export data to csv file

Use the following code to export data to the csv file:

string attachment = "attachment; filename=MyFilename.csv";
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "text/csv";
Response.AddHeader("Pragma", "public");
Response.Write("hello world"); //data goes here;
Response.End();

No comments: