This problem can caused by the server sending HTTP response headers that tell the browser not to cache the response. It is common for developers to configure ASP or ASP.NET applications this way because they contain dynamic content. Telling the browser not to cache the page ensures it will always make a new request to the server and get the most up-to-date version of the page. However, in a page which generates an Excel file and streams it to the client, it is better NOT to turn off client-side caching because the file needs to stay around long enough for the browser to pass it to Excel.
Even if the server has told the browser not to cache the file, the actual behavior may be different on different client machines. On certain clients, the temp file will remain long enough for Excel to open it. But on some client configurations, the spreadsheet gets deleted immediately by the operating system and Excel will not be able to find it.
The HTTP headers which control client-side caching may have been set either in your ASP or ASP.NET code or in IIS. The solution is to turn off these HTTP headers, either by removing the lines of code, or disabling the settings in IIS.
In Your Code
By default, ASP and ASP.NET do not add any headers to control browser caching behavior. If the headers have been set in your page, you will see some combination of the following lines of code:
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
If you see these lines of code in your ExcelWriter page, remove them.
In IIS
The default IIS settings for a virtual directory do not cause the generation of HTTP headers that affect client-side caching behavior. However, if you are experiencing this problem and there is nothing in your code, it is a good idea to check IIS. If IIS settings are causing the headers to be generated, you will see something like this in the "HTTP Headers" tab in the properties dialog of your virtual directory:
To turn off these settings, uncheck "Enable Content Expiration" If you prefer to keep the "Enable Content Expiration" settings for all your other non-ExcelWriter pages, you can do the above step in the "properties" dialog for the specific ExcelWriter page rather than for the application as a whole.
|