This project has moved and is read-only. For the latest updates, please go here.

How do I get my ASHX file to serve out .xslx instead of .xls files

Jul 29, 2012 at 8:48 AM

The Excel file downloads but then Excel complains that 'The file you are trying to open 'MySpreadsheet.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 click 'Yes' the spreadsheet opens fine but I don't want the annoying message every time my users download their spreadsheets.

If I change the file extension in Web.config to '.xlsx', then the file name of resulting file that gets downloaded becomes 'MySpreadsheet.xlsx.xls'

I'd be grateful for any help please.




Jul 31, 2012 at 8:28 PM

Hi hastings,

You need to use the DoddleReport.OpenXml package, which includes an enhanced ExcelReportWriter that will remove this warning. Make sure you register this writer in web.config with the .xlsx extension if you use the ReportResult in MVC. The nuGet package will do this for you if you use NuGet.