January 25, 2011

Forcing Internet Explorer to Download A Visualforce Page - WTF

Second post in two days – fastest updates ever for this blog. Anyway, sometimes you want to use Visualforce to return a file to a user, be it an excel file or outlook calendar item for example. You've probably gotten as far as specifying the content type in the page tag and then some bright spark has fired up that most cursed of browsers, Internet Explorer. They'll soon be telling you that Internet explorer is refusing to download the file you're creating – the solution to this annoyance (at least it was the solution for us and a few others I've seen online)? Specify cache="true" in the page tag too.

That's it. I have no idea why IE should need this and I'm not about to spend the time looking into it because frankly I like to spend as little time as possible dealing with IE and it's various idiosyncrasies. Just for the sake of an example, here's the full page tag we're now using in our Visualforce page:

<apex:page controller="QVFC_CalandarCreate" action="{!init}" contenttype="text/calendar#Calander.vcs" cache="true">