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 May 13 at 13:32
  • @GaneshSanap that thread talks about lretrieving items inside a list, Here I want items isnside a folder
    – None
    May 13 at 13:50
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, privacy policy and cookie policy

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