SharePoint Blog

Creating WebTemplate for SharePoint 2013 (OnPrem)

I was surprised to find that the creating a WebTemplate (instead of a full blown Site Definition) is so poorly documented. There are a couple of really extensive blogs around, but still they don’t unveil the utmost important detail of how to provision the ONET.XML whilst avoiding receiving a 0x8107026E error. If this is the reason you’re here then you better make sure that you named the SharePoint Emtpy Element Item so that it matches your WebTemplate’s name. If you do receive this error (and according to Google, many do) a quick analysis of SharePoint’s ULS Log does give away the clue: Failed to open the file ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\Template\Features\TeamSiteTemplate_MyFancyWebTemplateFeature\MyFancyWebTemplate\onet.xml’. From this it follows that SharePoint looks in the Feature’s folder for a sub folder that bears the name of the WebTemplate and expects to find the ONET.XML file in this folder. This immediately brings to attention another important fact. The ONET.XML file should be added to Empty Element item in your Visual Studio Project. This is a little bit worrying because normally you’d want to introduce files to SharePoint by adding a module. However, in this case you add the ONET.XML below your Empty Element item in which you define your WebTemplate. To ensure that the ONET.XML file gets deployed to the feature’s folder on the drive you need to change it’s Deployment Type property to Element File. Once this is done you should be able to deploy your WebTemplate using a Farm Scoped Feature and it will generally available when creating new sites.

One last interesting thing here is the fact that you cannot use WebTemplates for Feature Stapling. But if we provide our own ONET.XML we really don’t miss this, because we can activate the features here! Even though this is not the only contraint, WebTemplates are a rather helpful instrument for creating custom Site Templates without losing the upgradeability completely. This is mainly achieved because they’re based on out-of-the-box templates e.g. STS#0. However, to use them when creating sites using PowerShell, you’ll need to get accustomed to rather akward naming conventions. The Template ID of your WebTemplate is a concatenation of the Feature ID and the WebTemplate name e.g. “{11111111-1111-1111-1111-111111111111}#MyFancyWebTemplate”.

Copyright ©2012. All Rights Reserved.