sharepoint-2013camlcsomsharepoint-clientobject

CSOM Caml Query to return list folder sub items


I'm trying to return only list items for a given list folder. However each time i execute the following I get all items in the list. What's the easiest way to only get list items for a particular folder of a SharePoint list?

CamlQuery camlQuery = new CamlQuery
{
    ViewXml = "<View Scope=\'Recursive\' />",
    FolderServerRelativeUrl = "/Design Items"
};

ListItemCollection listItemCollection = list.GetItems(camlQuery);

I was sure if I needed the list name in the FolderServerRelativeUrl property so I've tried the following

FolderServerRelativeUrl = "/[ListName]/Design Items"
FolderServerRelativeUrl = "/Lists/[ListName]/Design Items"

Thanks,


Solution

  • You need to give the full server relative URL. If your site URL is https://contoso.com/sites/sitename/ then it should be like

    FolderServerRelativeUrl = "/sites/sitename/Lists/[ListName]/Design Items"
    

    you can also get the relative URL from ClientContext object like

     FolderServerRelativeUrl = ClientContext.Url+"/Lists/[ListName]/Design Items"