Speak out my mind

Menu

How to download a file from Sitecore Sheer UI Popup

I had this case where you need to download a file from a Sitecore Sheer UI Popup, like a PDF file or Excel Sheet directly from the browser without using the SaveAs dialog. The first thing that comes to your mind is to use the HttpResponse to download the stream file as the following:

You should not be surprised if no matter you tried to do so, the file will not be there!! As the popup will not allow writing the response (the response would be empty and no files are there). What I did to overcome this issue after trying different approaches and solutions is to use an IFrame and call the download code above in the page load. So what happens here is that the download button will read the file and store file information in the session (you can use any format, these used here for more clarification) and build up the IFrame and call the SheerResponse.Eval to call the IFrame page. Once all are downloaded, you can clear the session.

It took time to figure out this solution so I hope it would be helpful🙂