Sites and Sub-sites

By SharePoint object model, how we can get all the sites with sub sites and the top-level sites alone separately.

The following snippet which returns all the sites and sub-sites from the site collection.

SPSite site=new SPSite.AllWebs;

and if we want only the top-level sites from the sitecollection, we have to call the SPWeb object.

SPWebCollection webs=site.RootWeb.Webs;

and webs[0].Webs; returns the sub-sites from that particular web object.

Shantha Kumar
Shantha Kumar
Articles: 280


  1. I ran across your wetibse last week and started to follow your posts consistently. I haven’t commented on any kind of blog wetibse just however but I was considering to start soon. It is truly exciting to in fact contribute to an post even if it’s only a blog. I genuinely don’t know exactly what to write other than I genuinely loved reading through a couple of of your articles. Fantastic articles for confident. I will maintain visiting your weblog regularly. I learned a good deal from you. Thanks!

Comments are closed.