1

I'm trying to access the documents in a specific folder in a SharePoint document library. the library has multiple folders but I do know the name of the folder.

here is an example of the file tree (I want to access al the files inside the Folder_4:

  • MyDocLib
    • document_Acorn.pdf
    • document_ApplePie.pdf
    • Folder_AppleTypes
      • document_Gala.pdf
      • document_HoneyCrisp.pdf
      • document_PinkLady.pdf
      • document_Jonathan.pdf
    • document_Mango.pdf
    • Folder_OrangeTypes
    • document_Watermellon.pdf

I have this CAML query which will get me the folder but when I try Recursive or RecursiveAll I can never get more than just the folder to show up in the query. I believe I'm doing something wrong in the following query.

var camlQuery2 = "<View Scope='Recursive'>" + 
            "<Query>" + 
                "<OrderBy>" + 
                    "<FieldRef Name='Title' Ascending='True' />" +
                "</OrderBy>" + 
                "<Where>" + 
                    "<Eq>" + 
                        "<FieldRef Name='Title'/>" + 
                        "<Value Type='Text'>" +
                            "AppleTypes" + 
                        "</Value>" + 
                    "</Eq>" + 
                "</Where>" + 
            "</Query>" + 
        "</View>";

2 Answers 2

0

I found an answer that requires making another query. I change "Recursive" to "RecursiveAll" which will give me the folder I am wanting.

var camlQuery1 = "<View Scope='RecursiveAll'>" + 
        "<Query>" + 
            "<OrderBy>" + 
                "<FieldRef Name='Title' Ascending='True' />" +
            "</OrderBy>" + 
            "<Where>" + 
                "<Eq>" + 
                    "<FieldRef Name='Title'/>" + 
                    "<Value Type='Text'>" +
                        "AppleTypes" + 
                    "</Value>" + 
                "</Eq>" + 
            "</Where>" + 
        "</Query>" + 
    "</View>";

From that I will extract the "UniqueId" then I use that Id in a query to get all items with the "ParentUniqueId" that match the UniqueID.

var camlQuery2 = "<View Scope='Recursive'>" + 
        "<Query>" + 
            "<OrderBy>" + 
                "<FieldRef Name='Title' Ascending='True' />" +
            "</OrderBy>" + 
            "<Where>" + 
                "<Eq>" + 
                    "<FieldRef Name='ParentUniqueId'/>" + 
                    "<Value Type='Text'>" +
                        "{A1P2P3L4-E5T6-Y7P8-E9S0-1UNI2QUE3ID4}" + 
                    "</Value>" + 
                "</Eq>" + 
            "</Where>" + 
        "</Query>" + 
    "</View>";

This will give only the items inside the folder except other subfolders.

0

you should set camlQuery.FolderServerRelativeUrl = folder serverRelativeUrl

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='Recursive'>
                        <Query>
                        </Query>
                    </View>";
camlQuery.**FolderServerRelativeUrl** = folder.ServerRelativeUrl;

ListItemCollection listItems = list.GetItems(camlQuery);

clientContext.Load(listItems);
clientContext.ExecuteQuery();

fdi-sharepoint

Your Answer

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

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