3

There is a question about getting files/folders in some SharePoint folder. There is advice to filter list items by parent folder path. But how can I list files/folders in the List itself?
With REST I can only get list short name (e.g. 'AppPackages'). It allows me getting list content with REST service '_vti_bin/ListData.svc/AppPackages', but I cannot get neither readable name/title (e.g. 'App Packages') for showing it nor root folder path (e.g. '/Lists/AppPackages') for further filtering immediate files/folders.
I tried SOAP and I could get both title and root folder for list but cannot get short list name to use it further in REST calls. There is also no stable way to find correspondence between SOAP-obtained (title, root folder) pair and REST-obtained short name

Ideas and comments are very appreciated!

1

The following example demonstrates how to retrieve items from a specific folder in Library and print File/Folder Name and Url properties:

function getListItemsInFolder(webUrl,listName,folderPath) 
{
    var folderUrl = webUrl + '/' + listName + '/' + folderPath;
    return $.ajax({       
       url: webUrl + "/_vti_bin/ListData.svc/" + listName + "?$filter=Path eq '" + folderUrl + "'",   
       type: "GET",   
       contentType: "application/json;odata=verbose",
       headers: { 
          "Accept": "application/json;odata=verbose"
       }
    });
}


getListItemsInFolder(_spPageContextInfo.webServerRelativeUrl,'Documents','Orders')
.done(function(data)
{
    var items = data.d.results;
    for(var i =0; i < items.length;i++) {
      console.log(items[i].Name);  
      console.log(items[i].Path + '/' + items[i].Name);       
    }
})
.fail(
function(error){
    console.log(JSON.stringify(error));
});
  • Well, the question was how to list items from the list itself when I do not know its folder path. In your example, I need to list items from 'Documents' list. Note that 'Documents' != '/Shared Documents' though they correspond each other. So var folderUrl = webUrl + '/' + listName + '/' + folderPath; is not always correct. I have added "ROOT" to the question caption for clarity. – andrii Dec 29 '14 at 6:38

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.