C# – SPSite Directory Selection (C#)

csharepointspsite

I have a code that is running through all the Sites that we have created in SharePoint and finding the Sites that have documentation. When I create the SPSite object (?), I am defining a specific directory, but no matter what I seem to do, the script always runs through all the Sites in SharePoint, not just the sites in the specified directory.

Here's what the line of code looks like:
using (SPSite site = new SPSite("http://www.mysite.com/myprojects/ABC/"))

I'm trying to get the sites in the ../myprojects/ABC/ directory, but I am getting all the sites within mysite.com

Any ideas or insights would be greatly appreciated.

Best Answer

The question is: what does your iteration code look like? If you do a site.OpenWeb(), then iterate recursively through the direct children using the SPWeb.Webs property, you should be fine.

Your behaviour sounds more like you are using site.AllWebs, which returns all sites (SPWeb) in the site collection.