How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?

How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?

Here we will discuss how we can retrieve site definition used by any SharePoint site using SharePoint 2016 server object model. The same code will work as is in SharePoint 2013 also. Here I am explaining in a windows application in my SharePoint server.


Also, you can read:
– How to create a site definition using Visual Studio 2013 in SharePoint 2013?

SharePoint Online Delete all Items from the list using JavaScript Object model

Content type in SharePoint 2016 tutorial

Whenever we want to create a site we used to select a template which comes from a site definition. Default site definitions are like STS, MPS, BLOG etc.

Below is the code which will display all the sub sites of a site collection and the corresponding site defintion used to create the site.

string s = string.Empty;

using (SPSite ospSite = new SPSite(“http://mypc:29024/sites/SPTraining/”))

{

SPWebCollection webs = ospSite.AllWebs;

foreach (SPWeb web in webs)

{

try

{

s+=”Site URL ” + web.Url.ToString() + ” :: “+ web.WebTemplate.ToString() + “\n”;

}

finally { web.Dispose(); }

}

}

label12.Text = s.ToString();

Once you run the code, it will display details like below:

How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?
How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?


Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →