Why showing error message while opening .xls file

Sukanya picture Sukanya · Mar 21, 2012 · Viewed 46.9k times · Source

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.

Answer

Adrian Platte picture Adrian Platte · Jan 11, 2013

This one might be an old post, but I've been searching answers for the same issue, and thought it could be useful. It looks it's not related to the way your application gives the xls file to the browser. It's an issue with Office 2007 excess of security.

Microsoft's KB article 948615 explains it:

When you open a file in Excel 2007, you receive a warning that the file format differs from the format that the file name extension specifies.

The only solution is to add en entry to the client's registry. I know that's not a real solution for a web application maybe with hundreds of users, but at least you can add a note to the page telling how to fix that annoying warning.