I have a need to recursivily display all subsites which a user only has explicit permissions to view. Trying to avoid pulling back all sites that have All Authenticated Users permissions. I found an excellent example, but I'm still new and trying to figure out permissions.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Collections.Generic;
using SharePoint2010.TestWebParts.WebParts.DisplaySubSiteLinks.Classes;
namespace DisplaySubSiteLinks
{
class SiteProperties
{
public string LinkName { get; set; }
public string LinkURL { get; set; }
public string SiteDef { get; set; }
}
public partial class DisplaySubSiteLinksUserControl : UserControl
{
List<SiteProperties> allSiteLinks = null;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
allSiteLinks = new List<SiteProperties>();
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb rootWeb = site.RootWeb)
{
CollectWebProperties(rootWeb, ref allSiteLinks);
}
}
linksData.DataSource = allSiteLinks;
linksData.DataBind();
}
private static void CollectWebProperties(SPWeb web, ref List<SiteProperties> allSiteLinks)
{
allSiteLinks.Add(new SiteProperties()
{
LinkName = web.Title,
LinkURL = web.Url,
SiteDef = web.WebTemplate
});
foreach (SPWeb childWeb in web.Webs)
{
CollectWebProperties(childWeb, ref allSiteLinks);
}
}
}
}