7

I am working on a very simple app on iOS that should basically allow the user to login (got that part working), then list only document libraries and allow user to navigate these and download files. On WP8 i used CSOM and it was a complete cakewalk. Reading a bit on the internet i found that my best bet would be to try and use ListData.svc with REST and then parse the XML returned (and i saw somewhere i may force it to return JSON!) to display the items to the user. Going through the xml with Internet Explorer i can see that the structure is rather consistent and i can parse it easily. The problem i have is the site level - my inital request is to just send an empty GET to ListData.svc which, if authenticated, returns the XML with all collections of the site. However, the xml contains no properties indicating whether the collection is, in fact, a folder or a list etc. Further to that, this returns some weird lists i didn't know existed on my Sharepoint as i haven't really worked with Lists and using C# folders never returned these. (E.g.

ContentTypePublishingErrorLog

ConvertedForms

etc).

How can i query ListData.svc to return the top level document libraries on the site?

  • As a matter of fact, i can't seem to be able to get any information about the top level entity (list) except for metadata, which would help me query the items below, but not the actual top item! No baseitemtemplate, no title, not contenttype fields... – zaitsman May 17 '13 at 14:46
  • BTW, ListData.svc will return even lists that are marked as hidden. If you are stuck on 2010 and you are using JavaScript, then you are going to need to do a hybrid JSOM and ListData.svc solution. – Robert Kaucher Mar 17 '14 at 17:22
  • 1
    @RobertKaucher would that i could, this whole thing was implmeneted on a raft of mobile devices as-is, unfortunately. – zaitsman Mar 18 '14 at 8:56
1

Try this:

http://<site url>/_api/web/lists?$filter=BaseType eq 1

Where BaseType represents the type of list

  • Generic List = 0
  • Document Library = 1
  • Discussion Board = 3
  • Survey = 4
  • Issue = 5

MSDN

  • 2
    Check your URL. And he is specifically asking about ListData.svc so unless he is using 2013, your answer is inapplicable to the question. – Robert Kaucher Mar 17 '14 at 17:20
  • My mistake. I momentarily mixed up client.svc and listdata.svc. I'll leave the answer in case anyone needs it for 2013, but feel free to downvote it as it doesn't answer the question. – athom Mar 17 '14 at 18:07
  • @AlexT, yeah, as metnioned by Robert, this information is not what i was after. Indeed, the 2013 REST interface is much more of a pleasure to work with. – zaitsman Mar 18 '14 at 8:56
1

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.

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.