You need to sign in to do that
Don't have an account?

Download document from force.com sites
Hi all,
I am trying to download the documents of public folder rfom force.com site. I am using following approach for this.
value="{!URLFOR($Action.Document.Download, document.id)}"
But It opens the document in new tab and URL is shown in address bar. I want to download this instead of showing in new tab, because I don't want to show URL of the document.
could anyone please help me out.
when I used this "servlet/servlet.FileDownload?file={!Document.Id}", It gives me the same result
Did you put "/" on the beginning of servlet like "/servlet/...."?
Yes, I put "/" in the beginning.
Is it possible to download the document without opening it into new tab?
Use the below line and check. But you need to pass the SelectedVersionId in the link to download. So you need to query the ContentVersion sObject to get the specific ID and pass it in below highlighted context.
'/sfc/servlet.shepherd/version/download/{!Id}?asPdf=false'
If the document is in PDF format then,
'/sfc/servlet.shepherd/version/download/{!Id}?asPdf=true'
If it works, mark it as valid solution.
can you pls give me the example of this solution '/sfc/servlet.shepherd/version/download/{!Id}?asPdf=false'. It didn't work for me. or may be I am using this in a wrong manner!
I used this:
https://mydomain.force.com/HomePage/servlet.shepherd/version/download/015XXXXXXXXXXX?asPdf=false
where 015XXXXXXXXXXX is the Id of document
Hey
The above line will work only if you have the documents in Content Object. Iooks like you are using Document Object.
Rather you can try the previous suggestion but it will open in new tab since the target is set as _blank for the given url.
If you would like to open in the same tab then try to include target attribute in your script and set it as _self or _parent. It will work for sure.
Let me know if it works and mark it as solution.
Regards
SD
when I use "_self", it opened in current window instead of downloading document.
Can the document be downloaded automatically instead of opening in window?
This is how it works. I dont think there is any other way within salesforce.com.
Is there any way to authenticate that document URL(siteurl): "http://mydomain.force.com/Login/servlet/servlet.FileDownload?file=xyz" using apex code/visualforce page?
because my first page is login page and using my custom object values, cookies I am authenticating the website. but if that given document link is hacked then one can access any document of the public folders.
for example if following urls is leaked then one can access public documents:
http://pcr-developer-edition.ap1.force.com/sample/servlet/servlet.FileDownload?file=01590000001AKJT
so please suggest me a technique to authenticate the site url for document.
Kindly go through the link below, it may helps
This did not work for me, please post any other solution, if you can.