Getting started

SharePoint 2010 - Create Site Definitions and Site Templates with Visual Studio

This guide shows you step by step how to create a SharePoint Publishing Site Definition and two Site Templates.

This post is part of my SharePoint 2010 Branding training:

Site Definitions are XML files which are language dependent and therefore stored in different folders:

image

Each of the language dependent folders has a sub folder called XML:

image

Each Site Definition corresponds to a XML file and in order to create a new Site Definition you need to place a new XML file with the right markup in that folder.

1. Create a new solution called SharePoint2010.Publishing using the Site Definition template:

image

2. Deploy the solution to the Central Administration Web Application:   

image

Actually you need a running Site Collection to deploy the solution using Visual Studio. Since the goal is to create a new Site Collection using a custom Site Definition it doesn’t exist right now. Instead we deploy the solution to the Central Administration for now.

3. Open the ‘webtemp_SharePoint2010.Publishing.xml’ file:   

image

Remove the existing XML from the file.   

4. Add the following XML  to the file:

<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns:ows="Microsoft SharePoint">
  <Template Name="SharePoint2010.Publishing" ID="14099">
    <Configuration ID="0"
      Title="Homepage"
      Description="Creating a custom polishing site…"
      DisplayCategory="SharePoint Tutorial"
      Hidden="False"
      ImageUrl="/_layouts/images/SharePointTutorial/SPT_Homepage.png" 
      RootWebOnly="TRUE"/>

    <Configuration ID="1"
      Title="Content Site"
      Description="Creating a custom polishing site…"
      DisplayCategory="SharePoint Tutorial"
      Hidden="False"
      ImageUrl="/_layouts/images/SharePointTutorial/SPT_Content.png"
      SubWebOnly="TRUE"/>
  </Template>
</Templates>

5. Before I explain the parts just deploy the solution to the Central Administration.

6. Open Central Administration and click to create a new site collection:   

image

I think the picture explains the XML from above. The image URL property refers to an image lying under \14\TEMPLATE\IMAGES.

The first configuration can only be used to create Site Collections and the second one only to create sub sites.

7. In order to deploy an image for your custom Site Templates you need to add a mapped folder:   

image

8. Add 2 images:

image 

9. If you create a new site inside an existing Site Collection you should see the following if you have Silverlight installed:   

image

10. Open the onet.xml file:   

image

Remove the existing XML from the file. Since Microsoft knows best how to do this we are going to reuse the XML from an existing file. The XML is found in steps 11 and 12.

(Just for information: If you want to know how I found the following XML in steps 11 and 12 here's the way. 

Go to the \14\TEMPLATE\1033\XML folder and look for a file called ‘webtempsps.xml’ which includes the Site Definition for the out-of-the-box SharePoint publishing site.

Open ‘webtempsps.xml’ and you will find a template named ‘BLANKINTERNET’ around line 34. This refers to a folder named ‘BLANKINTERNET’:   

Inside \14\TEMPLATE\SiteTemplates\BLANKINTERNET\XML you’ll find an onet.xml file including a Publishing Site Template for reuse in steps 11 and 12.)  

image

Important: The template name ‘BLANKINTERNET’ in webtempsps.xml is the folder name where the onet.xml is stored! Otherwise onet.xml can’t be found during the creation of a new site.

11. Add the following XML to the file:

<?xml version="1.0" encoding="utf-8"?>
<Project Title="SharePoint2010.Publishing" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <NavBars>
  </NavBars>
  <Configurations>
  </Configurations>
  <Modules>
  </Modules>
</Project>

This is the main structure which will be extended with configurations and modules.

12. Add the following XML inside the configurations section:

<Configuration ID="0" Name="Homepage">
  <Lists/>
  <SiteFeatures>
    <Feature ID="A392DA98-270B-4e85-9769-04C0FDE267AA" />
    <Feature ID="7C637B23-06C4-472d-9A9A-7C175762C5C4" />
    <Feature ID="AEBC918D-B20F-4a11-A1DB-9ED84D79C87E">
      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
        <Property Key="AllowRss" Value="false"/>
        <Property Key="SimplePublishing" Value="false" />
      </Properties>
    </Feature>
    <Feature ID="F6924D36-2FA8-4f0b-B16D-06B7250180FA" />
  </SiteFeatures>
  <WebFeatures>
    <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
      <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
        <Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/CustomV4.master"/>
        <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/default.aspx"/>
        <Property Key="PagesListUrl" Value=""/>            
<
Property Key="AlternateCssUrl" Value
="~SiteCollection/Style Library/Custom.css" /> <Property Key="SimplePublishing" Value="true" /> </Properties> </Feature> <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA"> <Properties xmlns="http://schemas.microsoft.com/sharepoint/"> <Property Key="InheritGlobalNavigation" Value="true"/> <Property Key="IncludeSubSites" Value="true"/> <Property Key="IncludePages" Value="false"/> </Properties> </Feature> <Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" /> </WebFeatures> <Modules> <Module Name="ModuleHomepage" /> </Modules> </Configuration> <Configuration ID="1" Name="ContentSite"> <Lists/> <WebFeatures> <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416"> <Properties xmlns="http://schemas.microsoft.com/sharepoint/"> <Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/CustomV4.master "/> <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/default.aspx"/> <Property Key="PagesListUrl" Value=""/> <Property Key="AlternateCssUrl" Value="="~SiteCollection/Style Library/Custom.css" /> <Property Key="SimplePublishing" Value="true" /> </Properties> </Feature> <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA"> <Properties xmlns="http://schemas.microsoft.com/sharepoint/"> <Property Key="InheritGlobalNavigation" Value="true"/> <Property Key="IncludeSubSites" Value="true"/> <Property Key="IncludePages" Value="false"/> </Properties> </Feature> <Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" /> </WebFeatures> <Modules> <Module Name="ModuleContent" /> </Modules> </Configuration>

This is a lot of XML. We have 2 Site Templates… each of them references features which will be activated and configured during the creation of the site.

The first configuration includes ‘SiteFeatures’ which are site scoped features and activated during the creation of the site collection. The first configuration also includes ‘WebFeatures’ which are web scoped features which are also activated. Some of the features have properties which are set during activation like a Custom Master page ‘ChromeMasterUrl’ or custom CSS ‘AlternateCssUrl’.

All together each configuration can be described as a collection of settings of a SharePoint site. Each configuration references a module.

13. Add the following XML inside the modules section:

<Module Name="ModuleHomepage" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
  <File Url="default.aspx" Type="GhostableInLibrary">
    <Property Name="Title" Value="Homepage" />
    <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Homepage.aspx, ~SiteCollection/_catalogs/masterpage/Homepage.aspx" />
    <Property Name="ContentType" Value="TODO" />
    <Property Name="PublishingAssociatedContentType" Value=";#TODO;#TODO;#" />
  </File>
</Module>
<Module Name="ModuleContent" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
  <File Url="default.aspx" Type="GhostableInLibrary">
    <Property Name="Title" Value="ContentSite" />
    <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/ContentPage.aspx, ~SiteCollection/_catalogs/masterpage/ContentPage.aspx" />
    <Property Name="ContentType" Value="TODO" />
    <Property Name="PublishingAssociatedContentType" Value=";#TODO;#TODO;#" />
  </File>
</Module>

Again we have some complex XML. Each module can be seen as the default page which is created if you create one of the sites. Each page contains a name, a URL, a Page Layout and a Content Type (since content is stored in columns which belong to a content type).

14. Done.

The XML looks quite complex and huge but if you copy and paste it inside a Visual Studio project you can use the Visual Studio editor to open and collapse each node of the XML. This way it’s easier to read.

Summary

Using the Site Definition and Site Definition Configurations (Site Templates) you have a basic structure for implementing custom Columns, Content Types, Master Pages and Page Layouts so you can create a SharePoint Publishing environment. This environment can be highly adapted to the needs of authors and their processes.

blog comments powered by Disqus