How do I get a list of all subsites in a site

To get a list of all subsites in a site you can run the following pattern:

using (SPSite site = new SPSite(“[YOUR SITE COLLECTION URL]“))
{
    using (SPWeb web = site.RootWeb)
    {
        foreach (SPWeb subWeb in web.Webs)
        {
            // Do your thing…
        }
    }
}

No related posts.

Posted under Developer

This post was written by furuknap on December 9, 2008

Tags:

Do you want to contribute to this answer?

Name (required)

Email (required)

Website

Comments

More Blog Post