Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

Thanks.

share|improve this question

2 Answers 2

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

 
discard

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.