My blog has moved!

Visit http://blog.adamroderick.com/ and update your bookmarks.

Thursday, August 21, 2008

Get Every List in a Site Collection

This is from a forum post.


using (SPSite site = new SPSite("url") {

foreach (SPWeb web in site.AllWebs) {

foreach (SPList list in web.Lists) {

// do something...

}



web.Dispose();

}

}


Remember, the SPSite represents a site collection. The SPWeb represents a site. SPSite.AllWebs flattens the site hierarchy and returns all site. SPWeb.Lists returns all lists in a site.