I have a requirement to download multiple files on a click of visual force button.
i know below will work if its a single file
<a href="/servlet/servlet.FileDownload?file={!Documents}">
any clue about how to gain this for multiple files
There is no way standard way to achieve this goal. Apex Code doesn't have native "compressed file" APIs, so you can't compress the files together easily. HTML doesn't have a specification that allows a single link to represent multiple resources simultaneously. HTTP doesn't have a specification that allows a single request to serve multiple files without assistance from the browser (e.g. when resource X explicitly loads resource Y), and even if there were, Visualforce doesn't allow us to use arbitrary headers that we would need to support this logic. This leaves you with a couple of choices: 1) you could email the files to the recipient, 2) you could try to emit a ZIP file, or 3) you could try to concatenate the files into a ZIP file and provide a link to that resource. If email is a viable choice, you can use the interface provided by Apex Code for this. As for the others, they are non-trivial tasks, and I would probably skip trying them at all.
It will work if you want download selected document
function downloadFile() {
var arrayOfLinks =[]
j$('#downloadSelected .num ').each(function(i,val){
var checkbox_cell_is_checked = j$(this).closest('tr').find('input').is(':checked');
if(checkbox_cell_is_checked){
arrayOfLinks.push(j$(this).text());
}
});
downloadAll(arrayOfLinks);
}
function downloadAll(files){
//alert('Inside'+files.length);
if(files.length>0){
var file = files.pop();
//alert('Inside'+files.length);
window.open(file, 'Download');
setTimeout(downloadAll, 1500, files);
}
}