none
Get recently modified Documents throughout sharepoint site

    Question

  • Hi,

    I have to retrieve recently modified documents within a SharePoint Online site.

    Is it possible through APIs or CSOM ?

    I am using this code:

    function AllLibraries(siteUrl) { var clientContext = new SP.ClientContext(siteUrl); var oWebsite = clientContext.get_web(); this.collList = oWebsite.get_lists(); clientContext.load(collList); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } function onQuerySucceeded() { var listInfo = ''; var listEnumerator = collList.getEnumerator(); while (listEnumerator.moveNext()) { var oList = listEnumerator.get_current(); var BaseType = oList.get_baseType(); var Library = oList.get_title(); listInfo += 'Title: ' + oList.get_title() + ' BaseType: ' + oList.get_baseType() + '\n'; var defLib = ["Converted Forms","Form Templates","fpdatasources","Images","Issue List","List Template Gallery","Logs","Master Page Gallery","Pages","Site Assets","Site Collection Documents","Site Collection Images","Site Pages","Solution Gallery","Style Library","Theme Gallery","Translation Packages","Web Part Gallery","wfpub","Workflows"]; if(BaseType ==1) { Lib.push(Library); } } containsAll(Lib,defLib); function containsAll(Lib, defLib) { for(var i = 0 ; i < Lib.length; i++) { if($.inArray(Lib[i], defLib) == -1) { DocLib.push(Lib[i]); } } for(var i=0;i<DocLib.length; i++) { var listName = DocLib[i]; documentQuery(listName); } } } function onQueryFailed(sender, args) { // alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } function onQueryFailed(sender, args) { // alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }


     
    function documentQuery(listName) {
        var ctx = new SP.ClientContext.get_current();
        var oLibDocs = ctx.get_web().get_lists().getByTitle(listName);
        var caml = new SP.CamlQuery();
        caml.ViewXml = "<View Scope='RecursiveAll'></View>";
        //this.allDocumentsCol = oLibDocs.getItems(caml);
        allDocumentsCol = oLibDocs.getItems(caml);
        ctx.load(allDocumentsCol, "Include(FileLeafRef, ServerUrl)");
        ctx.executeQueryAsync(
        Function.createDelegate(this,function()
        {
          var libList= "";
          var ListEnumerator = allDocumentsCol.getEnumerator();
          while(ListEnumerator.moveNext())
          {
            var currentItem = ListEnumerator.get_current();
            var currentItemURL = domURL + currentItem.get_item('ServerUrl');
            libList += currentItem.get_item('FileLeafRef') + ' : ' + currentItemURL + '\n';
          }
          //alert(libList);
        }),
       
        Function.createDelegate(this,function(sender,args){
               // alert("Whoops: " + args.get_message() + " " + args.get_stackTrace());
            })
                
        );
    }




    Monday, March 27, 2017 10:26 AM

All replies