0

I'm currently writing a SharePoint hosted app that displays a treeview of a site collection on a site that is not the current. To do this I have an admin account that has permissions over both of these and calls are made via a Web API. Because the site collection is quite large I use lazy loading for the tree.

On the first click of a site it goes and gets all the subsites using web.Webs. It then checks permissions of the user logged into the site using this:

public static List<Subsite> GetChildren(string url, string username)
    {
        List<Subsite> children = new List<Subsite>();
        try
        {
            using (var clientContext = new ClientContext(url))
            {
                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();

                WebCollection webCollection = web.Webs;
                clientContext.Load(webCollection);
                clientContext.ExecuteQuery();

                foreach (Web subWeb in webCollection)
                {
                    ClientResult<BasePermissions> permissions = subWeb.GetUserEffectivePermissions(username);
                    clientContext.ExecuteQuery();
                    if (permissions.Value.Has(PermissionKind.EditListItems))
                    {
                        children.Add(new Subsite(root.Url + subWeb.ServerRelativeUrl, true));
                    }
                }
            }
            return children;
        }
        catch (Exception ex)
        {
            children.Add(new Subsite(ex.Message, false));
            return children;
        }
    }

This should return a list of all the subsites that the user has edit permissions on. However, it is also returning things that aren't subsites so to speak such as apps. When these are clicked to retrieve their subsites I get a 403 forbidden error (I do have permission to them).

I need a method so that these are not retrieved. I can simply ignore them if a 403 is returned but would prefer a cleaner way than this.

2
  • Do you mean that APP Webs are also returned and you don't need them? Jul 21, 2015 at 5:06
  • Yes, it's returning app webs.
    – Zoosmell
    Jul 21, 2015 at 5:10

1 Answer 1

4

You can check the Template type of a web object. If it is APP#0 you don't need to add it to List. The example here shows how to get the web template. https://stackoverflow.com/questions/19382310/using-client-object-model-how-to-fetch-the-web-template-name-and-web-templat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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