4

Hi everyone I have a Folder1 in my Server and inside that folder I have a Folder2 folder. So I am getting the file which is inside the Folder1 with this code:

public static SPClient.ListItemCollection GetPageItems(string listName = "Folder1")
{

    var pagesList = SharePointTools.ClientContext.Web.Lists.GetByTitle(listName);
    var pageItems = pagesList.GetItems(CamlQuery.CreateAllItemsQuery());
    SharePointTools.ClientContext.Load(pageItems);
    SharePointTools.ClientContext.Load(pageItems, list => list.Include(page => page.DisplayName));
    SharePointTools.ClientContext.ExecuteQuery();

    return pageItems;
}

So it is using GetByTitle method but I can't get the files which is inside my Folder2. So how I can get all files inside my Folder2? Can someone answer?

1
  • What makes you think you cannot get items from Folder2 sub folder in your example? CamlQuery.CreateAllItemsQuery returns all the items including from sub folders.. Oct 25, 2016 at 12:24

1 Answer 1

3

Try to use Caml Query with FolderServerRelativeUrl property

caml.FolderServerRelativeUrl = "/sitename/Documents/Folder1";

For more details check Get all files under subfolder in Shared Documents list - SP Object Model

Or using SPQuery

SPFolder folder = list.RootFolder.SubFolders["Folder 1"];
SPQuery query = new SPQuery();
query.Folder = folder;
query.ViewAttributes = "Scope=\"Recursive\"";

For more details check Get all Files from sub folder of a certain content type

1

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.