How include Salesforce file picker for a custom VF Page

I have a VF page where I need to attach files for an Email to be sent. I am using apex:inputFile for uploading the attachments. When you click on the “Browse” button next to the attachment, it opens up “My Computer” view to attach any files from your Hard Drive which is all fine.

What I want is, if a user clicks on Browse, he should get the Standard Salesforce attachment window, which also allows to attach documents from Salesforce folder.

See Image: pop-up

All the strike-out are Salesforce folders and if I select any one of them, I get the documents inside that folder.

Is there anyway to recreate this without writing the whole logic in a Custom controller for apex:includeFile ? How would you attach files saved in Salesforce folders.

Many thanks!

Answer

You won’t be able to change the behaviour of the standard file picker, as this renders to an HTML file input element which is rigidly controller by the browser, to stop nefarious code gaining access to the users file system. If you look at the Salesforce chatter file uploader, this generates two separate elements on the page, one for selecting a Salesforce file and another that uses a file input element to allow you to select from your computer:

enter image description here

You’d need to construct something like this in your Visualforce page, and present a dialog of the available Salesforce files to allow the user to select one of those to upload.

Attribution
Source : Link , Question Author : ankittaneja , Answer Author : Bob Buzzard

Leave a Comment