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, list => list.Include(page => page.DisplayName));

    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?

  • 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.. – Vadim Gremyachev Oct 25 '16 at 12:24

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

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.