SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out a way to check if a Site inside a Site Collection has sub sites in it.

To get sites inside a site collection, we can use the below code.

foreach (SPWeb siteobject in siteColName.AllWebs)

But how to check if siteobject has sub sites in it.?

Also, if it has subsites, then will it be treated as SPSiteCollection obejct?


share|improve this question
up vote 1 down vote accepted

Check if the count of int SPWeb.webs collection is greater than zero.

share|improve this answer
Yes, that was the required condition. Thanks for the help. – Thomas Mathew Nov 30 '12 at 13:29

You need SPWeb.GetSubwebsForCurrentUser, SubSite collection is SPWebCollection not SPSiteCollection, essentially a subsite is a SPWeb object

Also I think beside your requirement you should have a look at what really SPWebApplication, SPWeb, SPSite represent

Hope this helps :)

share|improve this answer
Thanks for the help. I am familiar with the above terms. The issue was a little confusion over a website having multiple subsite within. – Thomas Mathew Nov 30 '12 at 8:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.