I am using Excel 2010 I have the following code that I like to export to a xls file but I am getting the following message:
The file you are trying to open, 'Report.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is for the trusted source before opening the file. Do you want to open the file now?
Note that is still opens but not sure why I am getting the message
....
a.Fill(dtRecords);
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=Report.xls");
Response.ContentType = "application/ms-excel";
string tab = string.Empty;
foreach (DataColumn datacol in dtRecords.Columns)
{
Response.Write(tab + datacol.ColumnName);
tab = "\t";
}
Response.Write("\n");
foreach (DataRow dr in dtRecords.Rows)
{
tab = "";
for (int j = 0; j < dtRecords.Columns.Count; j++)
{
Response.Write(tab + Convert.ToString(dr[j]));
tab = "\t";
}
Response.Write("\n");
}
Response.End();