DEV Community

Cover image for SharePoint Site Templates
Ivan Porta
Ivan Porta

Posted on • Updated on • Originally published at Medium

SharePoint Site Templates

If you want to create a new SharePoint site using the Client Object Model, you can use the class WebCreationInformation to specify the site’s properties and then create it by adding the site to the Webs.

However, it is required to pass a unique TemplateType as a parameter. This parameter is a string and must match with one of the names of the available templates.

To get the list of all available templates, you can run the command Get-SpoWebTemplate in PowerShell. The table below gives an overview of all available templates.

image

As the libraries contained in the package Microsoft.SharePointOnline.CSOM don’t provide any enumerator for the available templates. I have created the following snippet.

using System.Runtime.Serialization;
namespace SharePoint.Models
{
    public enum WebTemplate
    {
        [EnumMember(Value = "GLOBAL#0")]
        GlobalTemplate,
        [EnumMember(Value = "STS#0")]
        TeamSite,
        [EnumMember(Value = "STS#1")]
        BlankSite,
        [EnumMember(Value = "STS#2")]
        DocumentWorkspace,
        [EnumMember(Value = "MPS#0")]
        BasicMeetingWorkspace,
        [EnumMember(Value = "MPS#1")]
        BlankMeetingWorkspace,
        [EnumMember(Value = "MPS#2")]
        DecisionMeetingWorkspace,
        [EnumMember(Value = "MPS#3")]
        SocialMeetingWorkspace,
        [EnumMember(Value = "MPS#4")]
        MultipageMeetingWorkspace,
        [EnumMember(Value = "CENTRALADMIN#0")]
        CentralAdminSite,
        [EnumMember(Value = "WIKI#0")]
        WikiSite,
        [EnumMember(Value = "BLOG#0")]
        Blog,
        [EnumMember(Value = "SGS#0")]
        GroupWorkSite,
        [EnumMember(Value = "TENANTADMIN#0")]
        TenantAdminSite,
        [EnumMember(Value = "ACCSRV#0")]
        AccessServicesSite,
        [EnumMember(Value = "ACCSRV#1")]
        AssetsWebDatabase,
        [EnumMember(Value = "ACCSRV#3")]
        CharitableContributionsWebDatabase,
        [EnumMember(Value = "ACCSRV#4")]
        ContactsWebDatabase,
        [EnumMember(Value = "ACCSRV#6")]
        IssuesWebDatabase,
        [EnumMember(Value = "ACCSRV#5")]
        ProjectsWebDatabase,
        [EnumMember(Value = "BDR#0")]
        DocumentCenter,
        [EnumMember(Value = "EXPRESS#0")]
        ExpressTeamSite,
        [EnumMember(Value = "OFFILE#1")]
        RecordsCenter,
        [EnumMember(Value = "EHS#0")]
        ExpressHostedSite,
        [EnumMember(Value = "OSRV#0")]
        SharedServicesAdministrationSite,
        [EnumMember(Value = "PowerPointBroadcast#0")]
        PowerPointBroadcastSite,
        [EnumMember(Value = "PPSMASite#0")]
        BusinessIntelligenceCenter,
        [EnumMember(Value = "SPS#0")]
        SharePointPortalServerSite,
        [EnumMember(Value = "SPSPERS#0")]
        SharePointPortalServerPersonalSpace,
        [EnumMember(Value = "SPSMSITE#0")]
        PersonalizationSite,
        [EnumMember(Value = "SPSTOC#0")]
        ContentsAreaTemplate,
        [EnumMember(Value = "SPSTOPIC#0")]
        TopicAreatemplate,
        [EnumMember(Value = "SPSNEWS#0")]
        NewsSite,
        [EnumMember(Value = "CMSPUBLISHING#0")]
        PublishingSite,
        [EnumMember(Value = "BLANKINTERNET#0")]
        PublishingSiteBlank,
        [EnumMember(Value = "BLANKINTERNET#1")]
        PressReleasesSite,
        [EnumMember(Value = "BLANKINTERNET#2")]
        PublishingSiteWithWorkflow,
        [EnumMember(Value = "SPSNHOME#0")]
        NewsHomeSite,
        [EnumMember(Value = "SPSSITES#0")]
        SiteDirectory,
        [EnumMember(Value = "SPSCOMMU#0")]
        CommunityAreaTemplate,
        [EnumMember(Value = "SPSREPORTCENTER#0")]
        ReportCenter,
        [EnumMember(Value = "SPSPORTAL#0")]
        CollaborationPortal,
        [EnumMember(Value = "SRCHCEN#0")]
        EnterpriseSearchCenter,
        [EnumMember(Value = "PROFILES#0")]
        Profiles,
        [EnumMember(Value = "BLANKINTERNETCONTAINER#0")]
        PublishingPortal,
        [EnumMember(Value = "SPSMSITEHOST#0")]
        MySiteHost,
        [EnumMember(Value = "ENTERWIKI#0")]
        EnterpriseWiki,
        [EnumMember(Value = "SRCHCENTERLITE#0")]
        BasicSearchCenter,
        [EnumMember(Value = "SRCHCENTERFAST#0")]
        FastSearchCenter,
        [EnumMember(Value = "TenantAdminSpo#0")]
        SharePointOnlineTenantAdmin,
        [EnumMember(Value = "visprus#0")]
        VisioProcessRepository,
    }
}
Enter fullscreen mode Exit fullscreen mode

To access the EnumMember attribute, we have to use the following Enum extension method.

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Reflection;
using System.ComponentModel;
namespace SharePoint.Extensions
{
    public static class EnumExtensions
    {
        public static string GetMemberAttributeValue(this Enum source)
        {
            Type enumType = source.GetType();
            if (!enumType.IsEnum)
            {
                throw new ArgumentException("source must be an enumerated type");
            }
            var memInfo = enumType.GetMember(source.ToString());
            var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
            if (attr != null)
            {
                return attr.Value;
            }
            return null;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Now, to create a new website on SharePoint would be enough using the following code:

WebCreationInformation webCreationInfo = new WebCreationInformation
{
  Title = "Title",
  Url = "url",
  WebTemplate = WebTemplate.ExpressTeamSite.GetMemberAttributeValue(),
  Description = "Description",
  UseSamePermissionsAsParentSite = true
};ctx.Site.RootWeb.Webs.Add(webCreationInfo);
ctx.ExecuteQuery();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)