How get Site Template name in SPSite, and Web Template name in SPWeb using C#
-
12-12-2020 - |
Question
I`m trying to analyse sharepoint site.
In SPSite Level, I want to get Site template name,
and In SPWeb Level, I also want to get web template name.
But I am a newbie in SharePoint, I`m not sure how can I find those things.....
Please somebody help me, explain about it or give some link about it
Thank you.
Solution
SPWeb.WebTemplate property Gets the name of the site definition or site template that was used to create the site.
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb("sites/blog"))
{
Console.WriteLine("Site definition: {0}", web.WebTemplate); // BLOG
Console.WriteLine("Web template ID: {0}", web.WebTemplateId); // 9
Console.WriteLine(web.WebTemplate == SPWebTemplate.WebTemplateBLOG); // True
Console.WriteLine(web.WebTemplateId == (int)SPWebTemplate.WebTemplate.Blog); // True
}
}
Console.ReadLine();
}
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange