Search This Blog

Monday, May 13, 2013

How to Create a Custom Site Defination in Sharepoint 2010

The process to create a custom site definition has not changed much since the last version of SharePoint, the only differences are the directory names and some of the XML in the WEBTEMP files.

Site Definition basics

Site definitions are located in the following folder on the SharePoint server:

C:\Program Files\Common Files\Microsoft Shared\web server
extensions\14\TEMPLATE\SiteTemplates


Each site definition has its own sub directory under this folder.

Inside each site definition sub directory the .aspx pages for the various web pages and lists that make up the site definition are stored.  Some of the new site definitions that come with SharePoint 2010 also include image files in these subdirectories.  The ONET.XML file specifies the various configurations and modules the site definition is made up of.  It is stored inside the XML subdirectory inside each site definition sub directory.

*Note: I think it is interesting that the SDK refers to Site Templates as the .stp files that are generated when you save a site as a template from the web UI, and the SDK refers to file based site templates as site definitions – yet this directory is named SiteTemplates.  This has been the case for a couple of versions now so I don't think we'll see it change in the future.

Site definitions are registered with SharePoint and made available via the WEBTEMP<NAME OF SITE DEFINITION>.XML file.  Theoretically, you could register a site definition with SharePoint with one of the out of the box WEBTEMP XML files, however this could introduce problems when service packs or newer versions of the product are released.  It is considered best practice to create your own WEBTEMP XML file to register your custom site definitions.

WEBTEMP XML files are located in the following folder on the SharePoint server:


C:\Program Files\Common Files\Microsoft Shared\web server
extensions\14\TEMPLATE\1033\XML



Creating a custom Site Definition in SharePoint 2010 – Manual Approach

Step 1: Clone an existing Site Definition
Step 2: Create the WEBTEMP XML fragment file to register the site definition with SharePoint
Step 3: Reset the application pool
Step 4: Create a site based on the custom site definition



Step 1: Clone an existing site definition


Navigate to the following directory on the SharePoint server in Windows Explorer:

C:\Program Files\Common Files\Microsoft Shared\web server
extensions\14\TEMPLATE\SiteTemplates



Copy the STS directory and paste it back into the same directory.  (You can copy any of the existing site definitions and use them as a baseline to create your own.)

Rename the Copy of STS directory to SAMPLE


Step 2: Create the WEBTEMP XML fragment file to register the site definition with SharePoint


Create a file called WEBTEMPSAMPLE.XML in the following directory:

C:\Program Files\Common Files\Microsoft Shared\web server
extensions\14\TEMPLATE\1033\XML


Put the following XML into the WEBTEMPSAMPLE.XML file:

<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="14.0.4514" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
 <Template Name="SAMPLE" ID="10001">
    <Configuration ID="0" Title="Sample Team Site" Hidden="FALSE"
        ImageUrl="/_layouts/images/stts.png" Description="A sample team site."
        DisplayCategory="Custom Site Definitions" >
    </Configuration>
    <Configuration ID="1" Title="Sample Blank Site" Hidden="FALSE"
        ImageUrl="/_layouts/images/stbs.png" Description="A sample blank site."
        DisplayCategory="Custom Site Definitions" AllowGlobalFeatureAssociations="False" >
    </Configuration>
    <Configuration ID="2" Title="Sample Document Workspace" Hidden="FALSE"
        ImageUrl="/_layouts/images/stdw.png" Description="A sample document workspace."
        DisplayCategory="Custom Site Definitions" >   
    </Configuration>
 </Template>
</Templates>

*Note: The DisplayCategory attribute of the <Configuration> element dictates which tab the configuration will appear on in the create new site web dialog. You can create your own tabs by putting your own values in this attribute (like I have done in the XML above and displayed in the screenshot below).  The screenshot below demonstrates how the Configuration element’s attributes (inside the WEBTEMP file) map to the create a site dialog.
 



Save the file.

Step 3: Reset IIS

Open a command prompt on the SharePoint server
Type in the command: iisreset
Wait for IIS to reset

Step 4: Create a site based on the custom site definition

Open Internet Explorer
Navigate to a SharePoint site on the server where you performed the steps above.
Click the Site Actions menu
Select New Site
Click the Custom Site Definitions tab on the left side of the create a site dialog to see the new site templates you registered with the SAMPLE site definition. 
Select one of the sample site templates you created.
Enter a title and URL
Click the Create button and your new SharePoint site is created.

Creating a custom Site Definition in SharePoint 2010 – Visual Studio 2010 Approach

Visual Studio 2010 simplifies the process by providing a project type specifically tailored for this purpose.  To create a custom site definition with Visual Studio 2010 first create a new Site Definition project.  See the screenshot below for reference.



Then set the path to the SharePoint site where you would like to deploy the site definition.



Once the project is created, you can see all the files needed to support a custom site definition in the Solution Explorer.


After you make edits to the files all you need to do is press F5 and the custom site definition is packaged into a WSP and deployed to the SharePoint server.  All that is left to do is to create a new site based on the custom site definition to verify it works properly.


Here you can see what the site template looks like when you use the out of the box Visual Studio 2010 Site Definition project type.


Site Defination 2007:



Site Definition basics
Site Definitions are located in the following folder on the SharePoint server: 

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates 

Each Site Definition has its own sub directory under this folder.
Inside each Site Definition sub directory the aspx pages for the various web pages and lists that make up the Site Definition are stored. The ONET.XML file that specifies the various configurations and modules the Site Definition is made up of is stored inside the XML subdirectory inside each Site Definition sub directory.

*Note: I think it is interesting that the SDK refers to Site Templates as the .stp files that are generated when you save a site as a template from the web UI, and the SDK refers to file based site templates as Site Definitions – yet this directory is named SiteTemplates. 

Site Definitions are registered with SharePoint and made available via the WEBTEMP<NAME OF SITE DEFINITION>.XML file. 

These files are located in the following folder on the SharePoint server: 

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML 

Creating a custom Site Definition in MOSS 2007
 
The following tasks are all you need to do to create a custom Site Definition in MOSS 2007.  

Step 1: Clone an existing Site Definition.
Step 2: Create the WEBTEMP XML fragment file to register the Site Definition with SharePoint.
Step 3: Reset IIS
Step 4: Create a site based on the custom Site Definition. 

Step 1: Clone an existing Site Definition.  
Navigate to the following directory on the SharePoint server in Windows Explorer:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates
Copy the STS directory and paste it back into the same directory.
Rename the Copy of STS directory to SAMPLE
Navigate to the following directory on the SharePoint server in Windows Explorer:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033
Copy the STS directory and paste it back into the same directory.
Rename the Copy of STS directory to SAMPLE 

Step 2: Create the WEBTEMP XML fragment file to register the Site Definition with SharePoint.  

Create a file called WEBTEMPSAMPLE.XML in the following directory:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML
Put the following XML into the WEBTEMPSAMPLE.XML file: 

<?xml version="1.0" encoding="utf-8" ?>
<!-_lcid="1033" _version="12.0.4017" _dal="1" -->
<!-_LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
<Template Name="SAMPLE" ID="10001">
<Configuration ID="0" Title="Sample Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a site for teams to create, organize, and share information quickly and easily. It includes a Document Library, and basic lists such as Announcements, Calendar, Contacts, and Quick Links." DisplayCategory="Custom Site Definitions" > </Configuration>
<Configuration ID="1" Title="Sample Blank Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a Windows SharePoint Services-enabled Web site with a blank home page. You can use a Windows SharePoint Services-compatible Web page editor to add interactive lists or any other Windows SharePoint Services features." DisplayCategory="Custom Site Definitions" > </Configuration>
<Configuration ID="2" Title="Sample Document Workspace" Hidden="FALSE" ImageUrl="/_layouts/images/dwsprev.png" Description="This sample template creates a site for colleagues to work together on documents. It provides a document library for storing the primary document and supporting files, a Task list for assigning to-do items, and a Links list for resources related to the document." DisplayCategory="Custom Site Definitions" > </Configuration>
</Template>
</Templates>  

*Note: The DisplayCategory attribute of the <Configuration> element dictates which tab the configuration will appear on in the Template Selection section of the create site web page. You can create your own tabs by putting your own values in this attribute (like we have done here).
Save the file. 

Step 3: Reset IIS
Open a command prompt on the SharePoint server.
Type in the command: iisreset
Wait for IIS to reset 

Step 4: Create a site based on the custom Site Definition.  
Open Internet Explorer
Navigate to the Sites Directory in your SharePoint portal (http://SharePointServerName/SiteDirectory)
Click the Create Site Link
Fill out the information on the form.
Notice at the bottom of the page in the Template Selection section the new Custom Site Definitions tab.
Click this tab and select one of the available configurations.
Click the Create button.

 

No comments:

Post a Comment