In my asp.net, C# application we are generating and downloading .xls file. But when I'm trying to open, it's giving a message
"The file you are trying to open, 'filename.xls', 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?"
If I press 'Yes' it's opening. I changed the file extension to .xlsx, still same message. Can anyone tell me why this is happening? I've added .xlsx MIME type extension in IIS manager with MIME Type as application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Still it's showing the same message. Please suggest how can I get rid off it.
Do you completely create the xls file or do you copy and fill a template xls file ? An incorrect format template file may cause the problem.
Also, what provider do you use to fill your file ? - Microsoft.ACE.OLEDB.12.0 for xlsx/xlsm ? - Microsoft.Jet.OLEDB.4.0 for xls ?
An incorrect provider/extension combination may cause the problem.
According to your comment, here is a part of code where I have done that in the past : ( commented some of the lines as I don't remember why they where useful )