Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loadFiles("Documents/2013",
- function(files) {
- var zip = new JSZip();
- zipFiles(zip,files,0,function(content){
- console.log('Done.');
- saveAs(content, "archive.zip");
- });
- },
- function(sender,args){
- console.log(args.get_message());
- }
- );
- function zipFiles(zip,files,index,complete){
- index = index || 0;
- var curFile = files.get_item(index);
- JSZipUtils.getBinaryContent(curFile.get_serverRelativeUrl(), function (err, data) {
- if(err) {
- throw err; // or handle the error
- }
- zip.file(curFile.get_name(), data, {binary:true});
- index++;
- if(index < files.get_count()) {
- zipFiles(zip,files,index,complete);
- }
- else {
- zip.generateAsync({type:"blob"})
- .then(function(content) {
- complete(content);
- });
- }
- });
- }
- function loadFiles(folderUrl,success,error){
- var ctx = SP.ClientContext.get_current();
- var web = ctx.get_web();
- var folder = web.getFolderByServerRelativeUrl(folderUrl);
- var files = folder.get_files();
- ctx.load(files);
- ctx.executeQueryAsync(
- function() {
- success(files);
- },
- error);
- }
Add Comment
Please, Sign In to add comment