SPWeb.WebTemplate property

Gets the name of the site definition or site template that was used to create the site.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public ReadOnly Property WebTemplate As String
    Get
'Usage
Dim instance As SPWeb
Dim value As String

value = instance.WebTemplate
public string WebTemplate { get; }

Property value

Type: System.String
A string that contains the name of the site definition. This value corresponds to the Name attribute of the Template element in Collaborative Application Markup Language (CAML).

Remarks

The possible values for this property are also available as constants in the SPWebTemplate class. For example, the name of the site definition for a wiki site is "WIKI", which is also the value of the constant SPWebTemplate.WebTemplateWIKI.

When you create a custom site template by saving a site as a template and then create a new site from that template, the WebTemplate property contains the name of the site definition from which the custom template derives, not the name of the custom template. Thus if the site that was used to create a custom template was itself created from the standard team site definition, the WebTemplate property of all sites that are created from the new template will return "STS" (or the value of the constant SPWebTemplate.WebTemplateSTS).

Examples

The following example is a console application that prints the values of the WebTemplate and WebTemplateId properties of a website that was created with the built-in "Blog" site definition. The application assumes that [http://localhost/sites/blog] is a valid URL for a SharePoint Foundation website.

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();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

Namespace Test
   Friend Class ConsoleApp
      Shared Sub Main(ByVal args() As String)
         Using site As New SPSite("http://localhost")
            Using web As SPWeb = 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 = CInt(Fix(SPWebTemplate.WebTemplate.Blog))) ' True
            End Using
         End Using
         Console.ReadLine()
      End Sub
   End Class
End Namespace

See also

Reference

SPWeb class

SPWeb members

Microsoft.SharePoint namespace

WebTemplateBLOG

WebTemplateMWS

WebTemplateSTS

WebTemplateWIKI

SPWebTemplate.WebTemplate