2 added 1511 characters in body
source | link

It seems there is no straightforward way to distinguish when using SharePoint 2010 REST Inteface (listdata.svc). You could consider the following solutions that demonstrate how to retrieve Library names

Option 1

It consists of:

  • perform request to /_vti_bin/listdata.svc/$metadata endpoint
  • retrieve list/library name from EntitySet element Name attribute
  • verify whether EntityType element contains <Property Name="Name" .. /> element to distinguish Libraries from Lists

JavaScript example:

function getLibraryNames(webUrl,complete)
{
    $.ajax({
      url: webUrl + "/_vti_bin/listdata.svc/$metadata",
      success: function(data){
        var names = [];
        $(data).find('EntityContainer EntitySet').each(function(){
            var name = $(this).attr('Name');
            var entityTypeName = $(this).attr('EntityType').replace('Microsoft.SharePoint.DataService.','');

            var propertyNameNode =  $(data).find('EntityType[Name="' + entityTypeName + '"] Property[Name="Name"]');
            if(propertyNameNode.length > 0)
               names.push(name);   
        });
        complete(names); 
      } 
    });
}



getLibraryNames(_spPageContextInfo.webAbsoluteUrl,
  function(names){
      for(var idx in names) {
         console.log(names[idx]);   
      }
  });  

Option 2

As an alternative approach you could leverage SharePoint SOAP Lists Web Service, in particular Lists.GetListCollection Method to return the names and GUIDs for all lists in the site.

As an alternative approach you could leverage SharePoint SOAP Lists Web Service, in particular Lists.GetListCollection Method to return the names and GUIDs for all lists in the site.

It seems there is no straightforward way to distinguish when using SharePoint 2010 REST Inteface (listdata.svc). You could consider the following solutions that demonstrate how to retrieve Library names

Option 1

It consists of:

  • perform request to /_vti_bin/listdata.svc/$metadata endpoint
  • retrieve list/library name from EntitySet element Name attribute
  • verify whether EntityType element contains <Property Name="Name" .. /> element to distinguish Libraries from Lists

JavaScript example:

function getLibraryNames(webUrl,complete)
{
    $.ajax({
      url: webUrl + "/_vti_bin/listdata.svc/$metadata",
      success: function(data){
        var names = [];
        $(data).find('EntityContainer EntitySet').each(function(){
            var name = $(this).attr('Name');
            var entityTypeName = $(this).attr('EntityType').replace('Microsoft.SharePoint.DataService.','');

            var propertyNameNode =  $(data).find('EntityType[Name="' + entityTypeName + '"] Property[Name="Name"]');
            if(propertyNameNode.length > 0)
               names.push(name);   
        });
        complete(names); 
      } 
    });
}



getLibraryNames(_spPageContextInfo.webAbsoluteUrl,
  function(names){
      for(var idx in names) {
         console.log(names[idx]);   
      }
  });  

Option 2

As an alternative approach you could leverage SharePoint SOAP Lists Web Service, in particular Lists.GetListCollection Method to return the names and GUIDs for all lists in the site.

1
source | link

As an alternative approach you could leverage SharePoint SOAP Lists Web Service, in particular Lists.GetListCollection Method to return the names and GUIDs for all lists in the site.

The following example demonstrates how to retrieve Documents libraries in the site:

function getListNames(baseType,complete)
{
    $().SPServices({ 
        operation: "GetListCollection", 
        completefunc: function( xData, Status ) {
            var names = [];
            $( xData.responseXML ).find("Lists > List").each(function() {
                var $node = $(this);
                if(parseInt($node.attr("BaseType")) == baseType)
                    names.push($node.attr("Title"));
            });
            complete(names);
        } 
    });
}  

Usage

getListNames(1,
  function(names){
      for(var idx in names) {
         console.log(names[idx]);   
      }
  });     

SPServices library is used which abstracts SharePoint's Web Services and makes them easier to use in JavaScript.