views:

149

answers:

2

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.

A: 

Have you looked at - http://msdn.microsoft.com/en-us/library/ms462161.aspx

dr
+1  A: 

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.

Paul-Jan
To add to Paul-Jan's point;new SPSite("http://www.mysite.com/myprojects/ABC/")Creates a reference to the site collection that hosts that URL. If that's the root web in a site collection .OpenWeb().Webs will give you what you want.If the site collection is actually http://www.mysite.com/ then you'll need to pull a reference to the SPWeb at /myprojects/ABC/ and then use .Webs
Mark