Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How to enumerate all WSS sites created under "http://<portal name>/s

  Asked By: Mindy    Date: Jan 18    Category: Sharepoint    Views: 2217

On my SPS portal, I create all of my WSS sites beneath the default
site creation url, "http:/<portal name>/sites/", and I would like to
enumerate all of those WSS sites in code.

I've attempted this syntax:

SPSite siteCollection = new SPSite(urlArg);
SPWebCollection sites = siteCollection.AllWebs;
foreach (SPWeb site in sites){
//do something.

If I input the complete WSS site url in the urlArg ("http://<portal
name>/sites/<wss name>"), this code works, but I want to enumerate
all of the sites created beneath "http:/<portal name>/sites/" instead.

If I input "http://<portal name>" or "http://<portal name>/sites" for
the urlArg, the code will enumerate the lists, areas, and sub-areas
at the portal level only, ignoring any WSS sites.



2 Answers Found

Answer #1    Answered By: Kyla Eckert     Answered On: Jan 18

try this

SPWeb siteDirectoryArea = null;
SPSite portalSite = new SPSite("http:/<portal name>/");
siteDirectoryArea = portalSite.AllWebs["SiteDirectory"];
SPList siteDirectoryList;
siteDirectoryList = siteDirectoryArea.Lists["Sites"];
SPListItemCollection listItems = siteDirectoryList.Items;

foreach(SPListItem item in listItems)

Answer #2    Answered By: Joshuah Huber     Answered On: Jan 18

You could also try this (assuming your portal  is the first virtual server on the box):

Dim gAdmin As SPGlobalAdmin = New SPGlobalAdmin
For Each site  As SPSite In gAdmin.VirtualServers(1).Sites
Dim web As SPWeb = site.RootWeb
' Stuff goes here

This will return your portal, all of the personal sites, and all the wss  sites. You could then look for "/sites/" in the url.