1

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);
    clientContext.Load<FolderCollection>(s‌​ubFolders);
    clientContext.ExecuteQuery();
    foreach (Folder subFolder in subFolders){
        folderinfo = new FolderInfo();
        folderinfo.Name = subFolder.Name;
        folderinfo.URL = subFolder.ServerRelativeUrl;
        result.Add(folderinfo);
    }
    return result;
}
3
  • Can you please post the code you created for this? Commented Jan 6, 2015 at 15:00
  • Using below code I'm adding each folder: Commented Jan 6, 2015 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;} Commented Jan 6, 2015 at 15:05

1 Answer 1

3

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));
    ctx.ExecuteQuery();
    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};
                result.Add(folderinfo);    
            }
    }
    return result;
}
10
  • Using this code: Commented Jan 7, 2015 at 8:32
  • bool regularFolder = subFolder.ListItemAllFields.ServerObjectIsNull != null && !subFolder.ListItemAllFields.ServerObjectIsNull.Value; Commented Jan 7, 2015 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. Commented Jan 7, 2015 at 8:35
  • 1
    ok, let me try with your code. Commented Jan 7, 2015 at 8:37
  • 1
    yes, your code is working fine. thanks for your help. Commented Jan 7, 2015 at 9:01

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.