Internet explorer changes xsl extension to xlt

When I download an Excel file in xls format from our server I get the warning below in Internet Explorer.

The Excel file is generated using Flexcel for .Net using the save method of the XlsFile class:
excel.Save(stream, TFileFormats.Xls);

The download link ends with the .xls extension but is changed when you click the link. Also when you do a save as from the link Internet Explorer changes the extension to .xlt and thinks it is an Excel template.

I am using Internet Explorer 9 on Windows 7. It makes no difference when I use IE9 in IE7 or IE8 compatibility mode.

Other browsers like FireFox and Google Chrome do not change the extension and do not give this warning below:

Web sites that use the "application/x-msexcel" or "application/vnd.ms-excel" MIME type to open web page content inside of Microsoft Excel may encounter the following warning prompt when the file attempts to open in Excel 2007:

"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)

If the user clicks Yes, the file will open as expected.  If the user clicks No, the file may open anyway, or may prompt a second time, and then not open if the user selects No again.  

Correction: also FireFox thinks my Flexcel generated xls file is a template.

See the following blog page from Microsoft that explains the problem:


http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx

Hi,

this is weird, I 've tried it here in a clean virtual machine, (Excel 2007, win7, ie9) and it works correctly. I am using the code:
           Response.AddHeader("Content-Disposition", "attachment; filename=Test.xls");
            Response.AddHeader("Content-Length", ms.Length.ToString());
            Response.ContentType = "application/excel"; //octet-stream";
            Response.BinaryWrite(ms.ToArray());

And it looks the filename has priority over the mime type.
If you have the line:
           Response.AddHeader("Content-Disposition", "attachment; filename=Test.xls");

Then the file must be xls, an xlsx will how the warning

If you change this line to be
 Response.AddHeader("Content-Disposition", "attachment; filename=Test.xlsx");

Then the file must be xlsx, and xls will show the warning.

But I haven't seen in any case an "xlt" file saved. I wonder what do you write in the "filename" part?
By the way, you can control if the file is a template or not with FlexCel by reading or writing to 
xls.IsXltTemplate

property. But as said, a standard xls file with an xls filename should work fine, I haven't seen any issues here.

A semi-related note: One known issue that happened with ie is that it might rename files to be "file[2].xls" when the file exists, and file[2].xls is not a valid Excel filename.  (xls filenames can't containt [ ] because it would confuse the formulas like =[file2.xls]!A1.
I am not sure if this know issue still applies in ie9 and actually I haven't seen for some time so it might be fixed, but it is the only ranaming issue I have seen. I haven't seen a file renamed to xlt.

I am not streaming directly from the server to the browser. I save the generated Excel file to the hard disk on the server and the user is presented with a direct download link to that file.

An example file name is: MngRpt-C-hd3yiv0pf1v.xls

Also I do not use the content type "application//excel" but in our IIS 7 mime mapping we use the microsoft recommended "application/vnd.ms-excel" for the "xls" extension. This is the IIS 7 default.

The download link in the browser does show the "MngRpt-C-hd3yiv0pf1v.xls" file name with the correct extension. As soon as I click the link Internet Explorer shows the given message. In the title bar of the dialog the filename is displayed as:  "MngRpt-C-hd3yiv0pf1v.xlt"

I will try if changing the mime-type to "application/excel" and setting the IsXltTemplate explicitly to false, makes any difference. All our server show this behaviour. Both the ones using IIS6 and IIS7.

Explicitly setting IsXltTemplate to false did not make any difference. This is as expected because it is false by default when creating a new file.


Changing the mime-type for "xls" from "application/vnd.ms-excel" to "application/excel" solved the problem!

At least it did for IIS7. Not for IIS 6 but that may be a IIS6 issue.

It is a little hard to diagnose this without being able to see how servers are configured, but some ideas:
1)
application/vnd.ms-excel should work, actually application/excel is older and probably the "correct" one today to use should be vnd.ms-excel.
What do you have in your client machine on this registry key?
HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/vnd.ms-excel

I have .xls (and it works fine here). Can you verify you don't have .xlt here?  This could be causing the problem.

What do you have in the "Content-Disposition" ? on the iis server?

2)
According to
http://msdn.microsoft.com/en-us/library/ms775148.aspx
<quote>
If the file is marked as "content-disposition=attachment" in the HTTP header, Internet Explorer treats the file name from the URL as final and does not rename it before placing it in the cache.
</quote>

So, can you try to conifgure IIS to send a "content-distribution=attachment" for the xls files, and this way ensure no renaming is done on the client?