I am trying to retrieve all items that are under a certain folder, in a document library.

This is what i have so far:

List DocumentsList = clientContext.Web.Lists.GetByTitle(list);
CamlQuery camlQuery = new CamlQuery();
camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='Recursive'>
                                    <FieldRef Name='FileDirRef'/>
                                    <Value Type='Text'>
                        <RowLimit Paged='TRUE'> 30 </RowLimit>
ListItemCollection listItems = DocumentsList.GetItems(camlQuery);

It is definitely a CAML query problem, I am just unsure of how to fix it as yet.

  • There was also bad casing for Eq operator. Being an XML dialect, CAML is case-sensitive. Commented Apr 23, 2019 at 10:50

6 Answers 6


I managed to get it working.

I changed the scope from "Recursive" to "RecursiveAll", RecursiveAll gets all files and all folders under the specified location.

The CAML query was replaced with

camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                "<Query>" +
                "<Where>" +
                            "<Eq>" +
                                "<FieldRef Name=\"FileDirRef\" />" +
                                "<Value Type=\"Text\">/ecm/Business/Business/Projects/IDECO_P01030000</Value>" +
                             "</Eq>" +
                "</Where>" +
                "</Query>" +
  • 4
    Sebastien, Your code worked not because you changed the string. It is because you changed the scope from "Recursive" to "RecursiveAll" As RecursiveAll gets all files and all folders under the specidified location.
    – user13753
    Commented Dec 21, 2012 at 7:40
  • 1
    hahah, so i see i asked this question when i was till very new to SharePoint :), thanks for pointing that out Commented Dec 24, 2012 at 8:00
  • @SebastienStettler : Hey If i want to check multiple conditions by putting <And> in this query how can i achieve that... Commented May 28, 2013 at 4:46
  • 2
    @RahulGokani if you have questions about a specific answer, please use our chat, not comments. Thanx! Commented Aug 26, 2013 at 12:41
  • this is worked ... <View Scope=\"RecursiveAll\"> .. in last two days i want to retrieve all task items in nested folders in task list and search google : summary task nested folders and so on... ( csom clientcontext ) Commented Feb 17, 2014 at 18:54

Try setting the FolderServerRelativeUrl property of the CamlQuery. See: here


you should also try to load all the folders and files. means


than you can get FolderCollection in Library

 FolderCollection FC = Document.RootFolder.Folders
 Foreach(Folder Fl in FC)
                FileCollection flc = fl.files;

Hops its help.


To get items from specific folder without receursive add to query this options:


Note to replace thelist/thefolder with actual relative url


Have you tried using comparison operator as 'Contains'

    <FieldRef Name='FileDirRef'/> 
    <Value Type='Text'> 
  • Contains operator is more resource intensive for SQL than Eq or In because the query engine cannot use an index. Commented Aug 4, 2015 at 14:36

This will get you all items in a list or library, including items in folders, support 5000+ items:

private async Task<List<ListItem>> GetAllListItems(ClientContext clientContext, List list)
    var result = new List<ListItem>();

    ListItemCollectionPosition itemPosition = null;
    while (true)
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ListItemCollectionPosition = itemPosition;
        camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
                                <FieldRef Name='Title'/>

        ListItemCollection listItems = list.GetItems(camlQuery);
        await clientContext.ExecuteQueryAsync();

        itemPosition = listItems.ListItemCollectionPosition;

        foreach (ListItem item in listItems)

        if (itemPosition == null)

    return result;
  • Woudln't it easier to use ´SP.CamlQuery.createAllItemsQuery()´ or SP.CamlQuery.createAllFoldersQuery()?
    – Emaborsa
    Commented Jan 25, 2021 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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