I'm using the sharepoint client object model for a small application. When I try to get all folders and items from the "Shared Documents"-library, it doesn't return all folders and files.


  private void SearchFolder(ClientContext context, SP.Folder folder, SP.List list, int niveau)
        SP.FolderCollection collection = folder.Folders;

        //Search subfolders
        foreach (SP.Folder tempFolder in collection)
            string tempFolderNaam = tempFolder.Name;
            SearchFolder(context, tempFolder, list, ++niveau);

        //Search this folder
        SearchFiles(context, folder, list, niveau);

I call this method with:
SearchFolder(context, list.RootFolder, list,0)
So it starts from the rootfolder and should get all (sub)files and (sub)folders

I've got 10 folders in the rootfolder and 1 subfolder in the first. It only returns 5 (4 are ok, one is "Forms"-folder)

Is there something i'm missing/did wrong? Or is this a bug?

Thanks in advance!

  • If it would help to see something else, just give a sign :) Commented Jul 20, 2011 at 13:52

1 Answer 1


Just based on looking at your code, rather than knowledge of the Client OM, I notice that you are recursively calling SearchFolder on the same client context object. While you are iterating through your collection object, you are Loading another collection and calling Execute, which might re-load the collection defined at the higher level in the call stack. It might be worth creating a new context object in the method rather than pass the existing one down through the call hierarchy, just to make sure that isn't causing a problem.

An alternative way of processing all documents is using CAML as described on msdn using the Scope='Recursive' attribute.

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.