We have an application that among other things will display an SSRS report through a reportviewer control. When exporting to excel, it creates a file that, when opened, has recently begun throwing the error:
Excel cannot open the file 'MyReportName.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
This appears to be an issue across all Office application formats, but the one I'm concerned about is Excel.
I've attempted to rename the file extension to .xls, but that did not prove valid. I've attempted to rename the extension to .zip and open in 7z, which typically works with xlsx files, but it doesn't open there either. The file is quite a bit smaller than we expect - just a few kb.
When opened directly from the SSRS server, the excel file produced can be opened fine.
Has anyone encountered this before?
Update:
There are some extra bytes at the start of the xlsx file.
Something is adding them into the stream that is sent to the browser. Remove them and the file opens just fine.
The last 2 bytes of this extra are 0D 0A, which is carriage return, line feed. So it looks like something is adding a text line in before sending the file. If I download the file I get 4 bytes and 0D 0A. Another file we examined had 5 bytes then 0D 0A, so it’s definitely something text.