2

I'm working on an UI feature for my SP2010 site and would like to display a number indicating how many documents were added to a specific library since the users last visit.

The UI will display a box on the left hand site of the screen, listing all document libraries on the current web and then how many documents were added since the users last visit.

I already know you can get all lists by doing:

var context = new SP.ClientContext.get_current();
var lists = context.get_web().get_lists();

But how can I get all document libraries as they are of a different type than SPList?

3

Give this a try,

function retrieveAllListProperties(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();
        listInfo += 'Title: ' + oList.get_title + ' BaseType: ' + 
            oList.get_baseType() + '\n';

      //if basetype is document library add your logic here...
    }
    alert(listInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

Reference

Def works for 2013 but should work on 2010 too.

  • Is there a way to know if it's a Default SP Lib? – yngrdyn Jul 14 '15 at 15:24
1

You can compare the template type of each list and see if it is based on document library. The syntax in ECMA script may be something like list.get_templateType. The enum for template types is SP.ListTemplateType

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy