In my visualforce page, having a section called 'Loan Documents' below it contains attachment. Need to download those attachment.
-
Click on the 'view' button next to the attachment.– PrajithCommented May 24, 2016 at 3:39
-
Thanks @stygon. But the view button show the document as new tab. Is there possible to download it. Please explain abut the possibilities in codes aswell– parthipanCommented May 24, 2016 at 4:16
-
Let's try right click - save link as– PrajithCommented May 24, 2016 at 4:17
-
Yes Stygon. i tried this works very well. But here i want to do it by clicking on Button - 'Download'. I am having limited experience in both visaulforce and apex.– parthipanCommented May 24, 2016 at 7:23
-
public PageReference getfile(){ if(uploadHistoryList.size() != null){ uploadHistory = [SELECT genesis_Account_Id__c, genesis_Application_Id__c, Loan_App_Id__c, Product_Related_Doc_Name__c, Document_URL__c, is_Doc_Verified__c, FROM Upload_History__c WHERE genesis_Application_Id__c =: application.Id AND Loan_App_Id__c =: loanApplication.Loan_ID__c ]; Attachment attachment = [SELECT Id, Body, ContentType, Name, ParentId FROM Attachment WHERE ParentId =: application.Id AND Name =: docNameForAction]; return null; }– parthipanCommented May 24, 2016 at 10:10
|
Show 2 more comments
2 Answers
try this:
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, YOURATTACHEMENTID)}" target="_blank">Download</apex:outputLink>
We use global action on attachment to allows download with stay in the same page.
try that (it works for me)
<apex:outputLink value="https://c.eu2.visual.force.com/{!Attachment ID here}" target="_blank">Download</apex:outputLink>
change https://c.eu2.visual.force.com/
by your organization link.