Renjith Kumaran

Renjith Kumaran

  • NA
  • 18
  • 3.5k

CSV not downloading

Nov 1 2015 7:37 AM
I want to download the csv and load a new page in a asp.net application. My code is like this. I am not getting any error. The page loads properly, but the csv is downloading.. Kindly help me to resolve..
 
Response.Clear();
Response.ClearContent();
Response.ContentType = "application/text";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.Charset = "";
string sep = "";
for (int i = 0; i <= dtsorted.Columns.Count - 1; i++)
{
Response.Write(sep + dtsorted.Columns[i].ColumnName + ',');
}
Response.Write("\r\n");
for (int i = 0; i < dtsorted.Rows.Count; i++)
{
sep = "";
for (int j = 0; j <= dtsorted.Columns.Count - 1; j++)
{
Response.Write(sep + dtsorted.Rows[i].ItemArray[j].ToString() + ',');
}
Response.Write("\r\n");
}
Response.SuppressContent = true;
Response.Redirect("VerifyLPODetails.aspx", false);
if (!Response.IsRequestBeingRedirected)
{
Response.Redirect("VerifyLPODetails.aspx", false);
}
 
}
}
 
 
 

Answers (1)