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
Nirmal ChristopherNirmal Christopher 

Download multiple files from attachment?

In contact I have member photos(JPEG files). I am creating a UI to display (using Apex and visualforce) all the attachments with a check box by it's side. The User will have the ability to choose the files they like to download and click a download button all the slected records should get  downloaded without viewing the record. how can i acheive this? I tried using java script i n the code its not working. \

Note:The files are getting downloaded automatically it the file is a word document or a XLS document. If the document is a Image file how we can do this?
Sonam_SFDCSonam_SFDC
hi Nirmal,

I would suggest you to use Wrapper class(http://wiki.developerforce.com/page/Wrapper_Class) to render the list of attachments on the VF page - this class will give the ability to users to choose whihc file they wish to download and you then need to create a method in your controller to download the selected files.

read on the below link to find how to download files thru a VF page:
https://developer.salesforce.com/forums?id=906F000000096oSIAQ
Nirmal ChristopherNirmal Christopher
Thanks Sonam,

   I created the Apex class and visualforce page and implemented the wrapper class everthing seems working fine. But the problem comes in downloading i can download individual files by using A href HTML tag but i find difficulty in downloading the multiple files simutaneously.n i tried to export the selected files to a XLS sheet usiing the content type attribute. All the data is coming properly except the images. any workaround will be highly appreciated. below is the code for ur reference  

<a href="/servlet/servlet.FileDownload?file={!a.id}" download="{!a.attname}">{!a.attname}</a>

the above line give a link once the link is clicked the browser starts the file download. but i want to download the multiple attachments. how to implement this using wrapper classes.
Deepak NagarajuDeepak Nagaraju
Thanks for the post Sonam!! Wrapper class really helped for the similar requirement I had. But as Nirmal said, I am also facing difficulty in downloading multiple files on one click. I am able to download only one file at a time. Any help will be a great help!!
shiva kumar 147shiva kumar 147
Hi all,
I need to download multiple selected files from Notes & attachment using VF and Apex, i displayed all files on vf page with checkbox. now i am downloading single file but i am unable insert selected file i.e select_List in VF page <!--apex:outputLink value="{!URLFOR($Action.Attachment.Download,a.attach.id )}" target="_blank">Download All</apex:outputLink> 

My controller method is:
 list<Attachment>att_select =[Select a.Id,a.ContentType,a.ParentId,a.Parent.Type,a.Parent.Name,a.OwnerId,
            a.Owner.Name, a.Name, a.LastModifiedDate, a.BodyLength From Attachment a where a.Id=:selectedFiles];
            system.debug('selected files are :'+att_select);
            for(Attachment att:att_select)
            {
                select_List.add(att.id); //a.attach.Id
            }
Any help ....How can i insert select_list in VF Page  instead of a.attach.id