0

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.

  • Out of disk space? New/recently updated antivirus solution? – AlwaysLearning Apr 21 '20 at 21:26
  • Disk space appears to be fine, and we've tried turning off the antivirus solution (and restarting services) but that didn't have any affect. – user2315960 Apr 22 '20 at 15:47
  • Added an edit as one of our developers noticed something being inserted at the top of the exported Excel file. Still don't know why this has begun happening. – user2315960 Apr 22 '20 at 15:48
  • Do you have a re-encrypting proxy appliance on your network, such as from BCSI? – AlwaysLearning Apr 22 '20 at 22:08
  • 1
    Update: It appears that there is a conflict between our IIS URL Rewrite module and ReportViewer. When we put any rule into the URL rewrite, the ReportViewer export appears to replace the string "Content-Length:" with a carriage return and line feed. So the actual integer value remains, and is now included in the file that is downloaded. Since Excel encounters that value first, instead of a marker it expects, it cannot open the file. I can remove the line that is the integer value and it opens, although sometimes it needs to be repaired. Removing the URL rewrite rules makes the files ok – user2315960 Apr 23 '20 at 14:54
  • Thanks AlwaysLearning, I am grateful for your response. We don't have such an appliance between our SSRS and Web Servers, – user2315960 Apr 23 '20 at 15:23

1 Answers1

0

I was having the same issue with The Content-Length being appended to the beginning of File exports in SRSS. The issue would stop when I disabled the URL Rewrite outbound rules. I found a solution based on this thread How to fix URL Rewriting for links inside CSS files with IIS7.

Short answer modify the web.config file to add rewriteBeforeCache="true" to your outbound rules tag.

<outboundRules rewriteBeforeCache="true">

This will stop the addition of the Content-Length to the beginning of the file.