I am adding list and library in treeview but it also displaying the "Forms", "Attachements", "Item" hidden folder in treeview.

Any one has any idea to hide that folder using client object model?

I'm using below code:

public static List<FolderInfo> GetFoldersInFolder(Folder folder, Web web, ClientContext clientContext) {
    List<FolderInfo> result = new List<FolderInfo>();
    FolderInfo folderinfo;
    FolderCollection subFolders = folder.Folders;clientContext.Load(folder);
    foreach (Folder subFolder in subFolders){
        folderinfo = new FolderInfo();
        folderinfo.Name = subFolder.Name;
        folderinfo.URL = subFolder.ServerRelativeUrl;
    return result;
  • Can you please post the code you created for this? – Amal Hashim Jan 6 '15 at 15:00
  • Using below code I'm adding each folder: – Suresh Chaudhary Jan 6 '15 at 15:03
  • public static List<FolderInfo> GetFoldersInFolder(Folder folder, Web web, ClientContext clientContext) {List<FolderInfo> result = new List<FolderInfo>();FolderInfo folderinfo;FolderCollection subFolders = folder.Folders;clientContext.Load(folder);clientContext.Load<FolderCollection>(subFolders);clientContext.ExecuteQuery();foreach (Folder subFolder in subFolders){folderinfo = new FolderInfo();folderinfo.Name = subFolder.Name;folderinfo.URL = subFolder.ServerRelativeUrl;result.Add(folderinfo);}return result;} – Suresh Chaudhary Jan 6 '15 at 15:05

How to exclude "system" folders using SharePoint CSOM

Folder class exposes Folder.ListItemAllFields property that specifies the list item associated with the folder, for "system" folders the corresponding list item does not exist.

The following example demonstrates how to verify whether the folder is regular or "system" folder:

bool regularFolder = subFolder.ListItemAllFields.ServerObjectIsNull != null && !subFolder.ListItemAllFields.ServerObjectIsNull.Value;

Fixed example

public static List<FolderInfo> GetFoldersInFolder(Folder folder, Web web)
    var ctx = web.Context as ClientContext;
    var result = new List<FolderInfo>();
    ctx.Load(folder.Folders, fcol => fcol.Include(f => f.Name, f => f.ServerRelativeUrl, f => f.ListItemAllFields));
    foreach (var subFolder in folder.Folders)
            if (subFolder.ListItemAllFields.ServerObjectIsNull != null && !subFolder.ListItemAllFields.ServerObjectIsNull.Value)
                var folderinfo = new FolderInfo {Name = subFolder.Name, URL = subFolder.ServerRelativeUrl};
    return result;
| improve this answer | |
  • Using this code: – Suresh Chaudhary Jan 7 '15 at 8:32
  • bool regularFolder = subFolder.ListItemAllFields.ServerObjectIsNull != null && !subFolder.ListItemAllFields.ServerObjectIsNull.Value; – Suresh Chaudhary Jan 7 '15 at 8:33
  • I am also getting null value for created folder or other than hidden folder like "Media Player" in "Style Library" . so your code is not working. Anything else I need to check. – Suresh Chaudhary Jan 7 '15 at 8:35
  • 1
    ok, let me try with your code. – Suresh Chaudhary Jan 7 '15 at 8:37
  • 1
    yes, your code is working fine. thanks for your help. – Suresh Chaudhary Jan 7 '15 at 9:01

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.