0

I can get all contents inside a SharePoint list like this:

List list = oWebsite.Lists.GetByTitle("Documents");
ListItemCollection Items = list.GetItems(CamlQuery.CreateAllItemsQuery());

This works fine, But now I want to get all the contents of a folder (not list). How can I achieve this?

FolderCollection folCol = list.RootFolder.Folders;
var myFolder = folCol.FirstOrDefault(x => x.Name == "my folder name");

I want to find all the content (child folder, child files, child folders and files inside child folders too) inside myFolder

2
  • Try with <View Scope=\"RecursiveAll\"> in CAML query as mentioned here Commented May 13, 2021 at 13:32
  • @GaneshSanap that thread talks about lretrieving items inside a list, Here I want items isnside a folder
    – None
    Commented May 13, 2021 at 13:50

1 Answer 1

1

Alternative 1:

         Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/MyRecordLibrary/Folder1/");
         clientContext.Load(folder);
         clientContext.ExecuteQuery();

         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();

Alternative 2:

    camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                "<Query>" +
                "<Where>" +
                            "<Eq>" +
                                "<FieldRef Name=\"FileDirRef\" />" +
                                "<Value Type=\"Text\">lib/Folder/Folder</Value>" + // I am not sure if you need an address relative to the document library or the site
                             "</Eq>" +
                "</Where>" +
                "</Query>" +
                "</View>";

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.