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.