Get the listing of sites under Sites directory in SharePoint Portal Server
Posted
Thu, Oct 20 2005 3:06 PM
by
Alexander Meijers
Did you ever wonder where those sites went if you create one under the Sites directory within SharePoint Portal Server? I did! If you try to list a sites by using the SPSite.AllWebs they will not show up. Why? So far as I can see they are created as "floating" sites. But there is a way to list them. The Sites directory is a Area and can be found easily.
First create a TopologyManager and retrieve the PortalSite object by using an Uri object.
TopologyManager topologyManager = new TopologyManager();
Uri uri = new Uri("http://localhost/");
PortalSiteCollection sites = topologyManager.PortalSites;
PortalSite portalSite = sites[uri];
Then get the PortalContext and use this to get the Guid of the SystemArea. The SystemArea is an enumeration providing you some starting points of Areas.
PortalContext portalContext = PortalApplication.GetContext(portalSite);
Guid homeGuid = AreaManager.GetSystemAreaGuid(portalContext, SystemArea.Home);
Based on the Guid its very easy to retrieve the actual Area object. And based on that Area object we retrieve the Sites Area object from its children.
Area homeArea = AreaManager.GetArea(portalContext, homeGuid);
Area sitesArea = homeArea.Areas["Sites"];
Loop through the AreaListings in this Area object and check if its type is ListingType.Site. The URL property contains the url to the created sites.
foreach(AreaListing listing in sitesArea.Listings)
{
if (listing.Type == ListingType.Site)
{
output.WriteLine(String.Format("{0} ({1})<br>", listing.Title, listing.URL));
}
}