I need to do the same thing as on this thread: Filter out hidden folder using client object model in sharepoint 2013

However my code needs to run on SharePoint 2010 and Sharepoint 2013.
I'm using the CSOM API 2013 and calling the method:

which throws the "Method or property ListItemAllFields does not exist" on SharePoint 2010.
Does anyone know any workaround for this issue?
I know that the method is not exposed in SharePoint 2010.

1 Answer 1


Ok, I think I got it.
Answer is the combination of CSOM and CAML query.
CAML query returns only user visible folder's without any tweaking which is exactly what I need.
This approach works on SharePoint 2010 and SharePoint 2013

Here's the code sample that recursively searches trough the SharePoint list and fills the TreeView:

    public TreeViewItem getRootTree(string libraryTitle) {
        Folder rootFolder = getRootFolder(libraryTitle);
        TreeViewItem rootItem = new TreeViewItem();

        rootItem.Header = rootFolder.Name;
        rootItem.Tag = rootFolder.ServerRelativeUrl;
        rootItem.FontWeight = FontWeights.Normal;
        addTreeChildren(rootFolder, rootItem);

        return rootItem;

    private void addTreeChildren(Folder parentFolder, TreeViewItem parentNode) {
        CamlQuery spQuery = new CamlQuery();
        String xmlCamlQuery = "<View><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";
        spQuery.ViewXml = xmlCamlQuery;
        spQuery.FolderServerRelativeUrl = parentFolder.ServerRelativeUrl;

        ListItemCollection items = currentLibrary.GetItems(spQuery);

        foreach (ListItem item in items) {
            Folder folder = getListItemFolder(item);
            TreeViewItem childItem = new TreeViewItem();
            childItem.Header = folder.Name;
            childItem.Tag = folder.ServerRelativeUrl;
            childItem.FontWeight = FontWeights.Normal;

            addTreeChildren(folder, childItem);

    private Folder getListItemFolder(ListItem listItem) {
        spClientContext.Load(listItem, li => li.ParentList.ParentWeb);

        Folder parentFolder = listItem.ParentList.ParentWeb.GetFolderByServerRelativeUrl((string)listItem["FileRef"]);
        return parentFolder;

This CAML query returns all first level folders:
String xmlCamlQuery = "<View><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";

This CAML query returns all subfolders (recursive search):
String xmlCamlQuery = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">1</Value></Eq></Where></Query></View>";

I use my own recursion to fill the library folder tree and ListItem is converted to Folder object like this:
Folder parentFolder = listItem.ParentList.ParentWeb.GetFolderByServerRelativeUrl((string)listItem["FileRef"]);
"FileRef" field is folder's server relative URL.

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.