Pergunta

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.

Code:

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

        //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!

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top