This is what i used to do for normal xls file format .
Response.ClearHeaders();
string attachment = "attachment; filename=EndOfYearReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
Response.Write(strEndOfYear.ToString());
Response.End();
but while opening the file i get the error:-
"The file you are trying to open, '[filename]', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" (Yes | No | Help)
so tried to upgrade to new version xlsx ..
Response.ClearHeaders();
string attachment = "attachment; filename=EndOfYearReport.xlsx";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.Write(strEndOfYear.ToString());
Response.End();
but not able to open the file this time ..
error was coming
Error: excel cannot open the file .xlsx because the file format or file extension is not valid
Please suggest