Download selected files as Zip file using JavaScript
0
I get a requirement where user needs to download the selected files from the SharePoint Document Library by zipping all of them. This I wanted to tr purely using JavaScript. The below will explain you how to download selected files as zip file using JSZip.
After surfing the internet I found this useful tool called as JSZip
And then i implemented the code below:
ConvertToZip.js:

 

It doesn’t end here, you need to add the below Javascript files and an image of the zip file:
I have added a module:

 

230b10_35beefc25cc44f50a773e11dd25dfede
230b10_0990bfc0f5f44417bf8bdd01d34df1d0
230b10_e96da70499d142628ad07be3e10340da

This article has 14 comments

  1. Matthew Thornicroft

    0

    0

    Works perfectly in SharePoint 2013 with a few tweaks. Made it work with document sets. Wish we could add compression – maybe another day!

    Thanks for sharing this.

    Matt

    • erkindunyar

      0

      0

      Hi Matt,
      I managed to deploy it SP13, due to the download image is for Office 365 it is missing,
      function AddZipIcon() {
      // for SP online
      $(“.ms-qcb-root ul li:nth-child(3)”).each(function () {
      $(this).first().before(” +
      ‘Zip’)
      });
      }

      could you share the code to display the ZIP.PNG “ZipDownloader/zip.png” please.

    • madhubabu

      1

      1

      this is working very well .but it is not working in publishing pages as below codes returns null values

      var items = SP.ListOperation.Selection.getSelectedItems(ctx);
      var ctx = GetCurrentCtx();
      var title = ctx.ListTitle;

      can anyone help me regarding this issue.

  2. Andrew

    0

    0

    Hi Joel D’souza,

    I ‘ d like to implement the feature in my Sharepoint 2013, but I don’t know how. Can you send me a little how to where I have to put the code etc.?

  3. erkindunya

    0

    0

    I managed to deploy it SP13 and applied some changes, due to the display image functions is for Office 365 as below, what is equvelent function for SharePoint 2013?

    function AddZipIcon() {
    // for SP online
    function AddZipIcon() {
    // for SP online
    $(“.ms-qcb-root ul li:nth-child(3)”).each(function () {
    $(this).first().before(” +
    ‘Zip’)
    });
    }

    could you share the code to display the ZIP.PNG “ZipDownloader/zip.png” please.
    Many thanks

    • Joel Dsouza

      0

      0

      Well, i haven’t created any function for SP 2013, you will need to add the icon using JQuery/JavaScript by finding the element in which you want to insert this icon

  4. Prince

    0

    0

    Above code is working from my side only for Google Chorme and Mozilla.
    I am using IE 11 here sometimes files are download and sometimes throws expection using JSZipUtils.getBinaryContent this method.

    Please suggest me .

Leave a Comment