Online Training On SharePoint
                      

Tuesday 2 June 2009

Finding the Site Definition used to create the Sites in SharePoint

I was working on a big site collection which was having more than 1000 different sub site created using different Site Definitions. I had a task to list all these sub sites and find out the site definitions used to create these sites.

This can be done easily using SharePoint Object Model. The below code will list all the sites and the definition used to create these sites:

SPSite site = new SPSite("SiteURL");
SPWebCollection webs = site.AllWebs;
foreach (SPWeb web in webs)
{
try
{
string template = web.WebTemplate;

Console.WriteLine(web.Url.ToString()+ " : " + template.ToString());
}
finally
{
web.Close();
site.Close();
}
}

No comments:

Related Posts with Thumbnails