You need to sign in to do that
Don't have an account?
Dynamic Visualforce Naming
I've been doing some work creating content in Visualforce that is rendered/opened in different formats (PDF, csv, excel etc). The few ways I have found to force rendering or download of the Visualforce page onload is to renderAs="PDF" or setting contenttype="text/csv" etc. The issue is during the load of the page, the page itself is saved using the naming convention of the Visualforce page, meaning you cannot specify the necessary extension.
I was wondering if anyone had a workaround or any ideas to force the save of the page to a dynamic name and specify a file extension (for instance force a Visualforce page named Report with contenttype="application/csv" save as {dynamicname}.csv).
My temporary work-around is having the file emailed as an attachment, as you can specify name of attachment and file extension dynamically in Visualforce templates. I would prefer the option to directly download rather then use this work-around. Anyone have any ideas?
You may be able to get what you want by specifying the name in the contenttype. Something like
contentType="text/csv#{!dynamicname).csv"
All Answers
You may be able to get what you want by specifying the name in the contenttype. Something like
contentType="text/csv#{!dynamicname).csv"
Awesome. thanks - that worked!
Hi, I have the similar requirement to save an output document that renderas PDF with a dynamic name. I tried using contentType="application/pdf#{!XXXXX.Name}.pdf" but it didn't work. Any suggestions?
Hello Maxforce, did you find a solution to this naming problem? I have a similar problem.
Hi Dikshant,
No I didn't find a solution, but I did a work around by directly attaching the PDF doc to the Attachments section when the user clicks on the button with the required naming convention.
Hi Dikshant,
I got the solution. You should not used renderAs="PDF" in the apex:page tag, you should use only contentType="application/pdf#{!NOW()}". But if you don't use renderAs it will not open the pdf, instead it will save directly in your system with the Dynamic name. Try it.