Tuesday, April 30, 2013

Retrieve all web site title and list title in current site collection in SharePoint

In this post we will discuss how to retrieve all web site title and list title of the current site collection using SharePoint 2010 object model.

Also you can check out my previous posts on Create custom page layout in SharePoint 2013, Fix width of master page in SharePoint 2010 and Create custom permission level in SharePoint 2013.

Below is the full code:

SPSite siteCollection = SPContext.Current.Site;

SPWebCollection collWebsite = siteCollection.AllWebs;
for (int i = 0; i < collWebsite.Count; i++)
{
    using (SPWeb website = collWebsite[i])
    {
        SPListCollection collList = website.Lists;

        for (int j = 0; j < collList.Count; j++)
        {
            Label1.Text += collWebsite[i].Title + "   " + collList[j].Title + ";
        }
    }
}

No comments:

Post a Comment