Get a list of all Top Level Sites in WSS
February 20th, 2006 // 5:52 pm @ Amar
If you have a WSS site with SelfServiceSiteCreation turned on, or you are creating sites programatically using SelfServiceSiteCreation process, it does not create subsites under the root WSS site. Instead it creates top level sites under the Virtual Server under which your root site exists. If you want a list of all such top level sites existing under a WSS Virtual Server, you can use the command line stsadm.exe -o enumsites -url http://WssSiteUrl
But… what if you want to get this list programatically. You cannot get this info from enumerating the subsites or subwebs of the root WSS site. In order to get it, you will need the help of the SPGlobalAdmin class. This piece of code might come handy. The code is in VB, but can easily be ported to C#
Private Sub ListTopLevelSites(ByVal RootUrl As String)Dim globalAdmin As SPGlobalAdmin
globalAdmin = New SPGlobalAdmin
Dim virtualServer As SPVirtualServer
virtualServer = globalAdmin.OpenVirtualServer(New Uri(RootUrl)) Console.WriteLine(“Found ” & virtualServer.Sites.Count & ” sites”) For Each site As SPSite In virtualServer.Sites
Console.WriteLine(site.Url.ToString())
Next
End Sub
For SPS it will not list the sites under the Site Directory ( which can be obtained using the Topology Manager ). Instead it will list the MySites created on the portal.
Category : SharePoint
http://
5 years ago
Hi
this article is informative. But is there any way where i can display details about the site
Regards
Amar Galla
5 years ago
Hi Madhavi,
Once you have the SPSite object, you can then query it to get more information about the sites. There are various properties which give you most of the details about a site, like its title, description, url, templates, lists created in it, etc…
Hope this helps.
http://
5 years ago
Hi can you give an example on the Topology Manager to get the list of Top Level WSS sites. I am a newbie and would like to know more about it.
Thanks in advance.
amar
5 years ago
Hi Neo,
For more on the Topology Manager check this page.
To get top level WSS sites, you don’t need the Topology Manager. It is used only to get the PortalContext object and use it forward. For WSS, just get the top level SPSite object e.g. SPSite topSite = new SPSite(“/”);
Once you have the top level site object, then you can iterate through the object model to get all the subsites. Just search for SPSite and SPWeb objects and you will find lots of material to achieve this.