Wednesday, September 7, 2011

Find the SharePoint web Template ID

The web template id can be found using object model or Power shell script.
Powershell script to find the specific web template details:
Open windows Powershell ISE to execute the comments/scripts. Load the SharePoint assembly if those are not loaded.
To load the SharePoint assembly
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
OR
This assembly can be referred using the “LoadWithPartialName” function which doesn’t require the full assembly information:
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

$web = Get-SPWeb http://portal
write-host "Web Template:" $web.WebTemplate " Web Template ID:" $web.WebTemplateId
$web.Dispose()
Above script can be stored as a .ps1 file and can be executed using SharePoint PowerShell window.

C# code to find out the web template details:
Server Object model can be used for finding out the web template details.
using System;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
using(SPSite site=new SPSite(@"http://sitecoll/"))
{
SPWeb web = site.RootWeb;
Console.WriteLine("Web Name : "+web.Title);
Console.WriteLine("Web Template Name : " + web.WebTemplate);
Console.WriteLine("Web Template ID : " + web.WebTemplateId);
Console.WriteLine("Web GUID : " + web.ID);
}
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine("Error: "+ex.Message);
}
}
}
}


4 comments: