function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Download document from sites

Hi all,

I am trying to download the documents of public folder rfom site. I am using following approach for this.




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.

use this custom link instead "servlet/servlet.FileDownload?file={!Document.Id}"

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?

S DigalS Digal

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.




If the document is in PDF format then,




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:


where  015XXXXXXXXXXX is the Id of document

S DigalS Digal



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.





when I use "_self", it opened in current window instead of downloading document.


Can the document be downloaded automatically instead of opening in window?

S DigalS Digal

This is how it works. I dont think there is any other way within


Is there any way to authenticate that document URL(siteurl): "" 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:


so please suggest me a technique to authenticate the site url for document.


This did not work for me, please post any other solution, if you can.