2

I am using C# at the backend and angularJS at the front. I have a requirement of downloading multiple files as separate downloads. Currently what I do is if there is multiple folder/files to be downloaded , we create a Zip file and upload to a sharepoint library and then download that zip file from that location.

But the problem now is that my clients settings prevent people from downloading files more than 500MB.So I am in search of alternate ways to download the multiple files. One of the options that was suggested was to download each file individually. so what i did was to get the URL of all the files to be downloaded and then call a method to download the file using the download link.Here is my code.

   $scope.downloadFile = function (resourceUrl) {
         $rootScope.exceptionLoaderCase = true;
         var isfile = resourceUrl.split('/').pop().split('.').length > 1
         if (resourceUrl.indexOf(_spPageContextInfo.webAbsoluteUrl) > -1 && !resourceUrl.endsWith(".aspx") && isfile) {

             var downloadRedirect = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/download.aspx?SourceUrl=" + resourceUrl + "&FldUrl=";
             window.location.href = downloadRedirect;
         }
         else {
             window.open(resourceUrl, "_blank");
         }
         $rootScope.exceptionLoaderCase = false;

     };

But when i use this method , Only one item that is passed to the function is getting downloaded. I cant seem to figure out the issue. It also doesn't work when I add a timeout to it.

Another option that I would want to try is to initiate downloads on rest API calls to the sharepoint server. But I am not sure of the possibility of returning multiple downloads from the server side api. Please respond If anyone have any suggestions or links that can help me get this done.

Any suggestion for any other approach is also welcome.

Thanks in advance.

1 Answer 1

0

The issue was because of Javascript. Only the last iterated value was being passed to the method , resolved that by calling the method as said in this article .

for(var i = 0;i < 10;i++){
    var j = i;
    setTimeout(function(){
       downloadFile(j);
    },1000);
}

and also had to change

window.location.href = downloadRedirect;

to

window.open(downloadRedirect, "_blank");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.