SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
If it would help to see something else, just give a sign :) – Ruben Herman Jul 20 '11 at 13:52
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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