I basically have put the following into my button click even handler, and it works mostly but it also writes out all the html of the page too in the CSV file. Is there a way to stop this?
StringBuilder sb = new StringBuilder();
sb.AppendLine("pkey,epsn,Cal. Date (UTC),Va Mult, Vb Mult, Vc Mult,Ia Mult, Ib Mult, Ic Mult, Ia Phase, Ib Phase, Ic Phase, CT Rating, CT Type, Cal By");
Response.ContentType = "application/csv";
Response.AddHeader("content-disposition", "attachment; filename=EPSn.csv");
Response.Write(sb.ToString());
foreach (DataRow row in dt.Rows)
{
sb = new StringBuilder((string)row[0]);
for (int i = 1; i < dt.Columns.Count; i++)
{
if (row[i] is DBNull)
sb.Append(",NULL");
else if (i == 2)
sb.Append("," + new DateTime((long)row[i]).ToString("G"));
else
sb.Append("," + row[i].ToString());
}
sb.AppendLine();
Response.Write(sb.ToString());