17 Sep 2011

Site Templates Development SharePoint

SharePoint 2010 provides many ways for defining site models.

You could have a site definition, which is a site model defined on the file system and stored under the folder SharePoint14_Root\TEMPLATE\SiteTemplates of every front-end server.

You could create a web template either using Microsoft Visual Studio 2010
Saving an already existing site instance through a specific page available in the Site Settings page (under the menu item Save Site As Template in the Site Actions menu group).

A web template can also be exported from SharePoint Designer 2010 as a .WSP package.


Native Site Definitions

Native site definitions are stored in the file system of the servers, in the SharePoint14_Root\TEMPLATES\SiteTemplates


The standard dialog for choosing the template for a new subsiteimage


SharePoint load model from the file name like WEBTEMP*.XML in the SharePoint14_Root\TEMPLATE\{IdCulture}\XML folder,


<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="14.0.4762" _dal="1" -->
<!-- _LocalBinding -->
<Templates xmlns:ows="Microsoft SharePoint">
<Template Name="GLOBAL" SetupPath="global" ID="0">
<Configuration ID="0" Title="Global template" Hidden="TRUE" ImageUrl=""
Description="This template is used for initializing a new site." ></Configuration>


The WEBTEMP*.XML files are just directories of site templates’ configurations. The actual configuration is included in an XML file, named ONET.XML, which is located in the XML subfolder
of every site definition

The ONET.XML file for the standard STS site template defining STS#0.

<Configuration ID="0" Name="Default" MasterUrl="_catalogs/masterpage/v4.master">
<List FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" Type="101"
QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx" />
<List FeatureId="00BFEA71-6A49-43FA-B535-D15C05500108" Type="108"
Folder;/AllItems.aspx" EmailAlias="$Resources:core,discussions_EmailAlias;" />
<!-- Code omitted for the sake of brevity -->
<Module Name="Default" />
<!-- BasicWebParts Feature -->
<Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
<!-- Three-state Workflow Feature -->
<Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
<!-- TeamCollab Feature -->
<Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
<!-- MobilityRedirect -->
<Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
<!-- WikiPageHomePage Feature -->
<Feature ID="00BFEA71-D8FE-4FEC-8DAD-01C19A6E4053" />

Site Definitions

Steps to manually create a custom site definition:

  1. You could simply copy an existing site definition folder  from SharePoint14_Root\TEMPLATES\SiteTemplates
  2. Change the ONET.XML file to select the lists definition to use for creating list instances, the modules to provision, and the features to activate
  3. Define a custom WEBTEMP*.XML file and copy it into the proper folder, within SharePoint14_Root\TEMPLATES\{IdCulture}\XML

In custom site templates you should use values equal to or greater than 10000 for the ID attribute, to avoid overriding the IDs of native templates



Site Definitions with Visual Studio


The New Project window of Visual Studio 2010 with the Site Definition project template highlighted.

“How to: Create a Custom Site Definition and Configuration,” available on MSDN Online at http://msdn.microsoft.com/en-us/library/ms454677.aspx

For the site definition, your only choice is a farm solution deployment

The template project outline is made up of the minimal contents for defining a site definition: an ONET.XML file, a WEBTEMP*.XML file, and a default.aspx home page.

Avoid activating the features into the deployment target site, it will be site admin task to use the site template.



Custom Web Templates

The list of available site models is made up of site definitions and web templates

A custom web template is created by exporting the definition of an existing site instance,
with or without its content, and storing the result into the content database as a sandboxed

AdjustHijriDays = "Integer"
AlternateCssUrl = "Text"
AlternateHeader = "Text"
BaseTemplateID = "Integer"
BaseTemplateName = "Text"
BaseConfigurationID = "Integer"
CalendarType = "Integer"
Collation = "Integer"
ContainsDefaultLists = "TRUE" | "FALSE"
CustomizedCssFiles = "Text"
CustomJSUrl = "Text"
Description = "Text"
ExcludeFromOfflineClient = "TRUE" | "FALSE"
Locale = "Integer"
Name = "Text"
ParserEnabled = "TRUE" | "FALSE"
PortalName = "Text"
PortalUrl = "Text"
PresenceEnabled = "TRUE" | "FALSE"
ProductVersion = "Integer"
QuickLaunchEnabled = "TRUE" | "FALSE"
Subweb = "TRUE" | "FALSE"
SyndicationEnabled = "TRUE" | "FALSE"
Time24 = "TRUE" | "FALSE"
TimeZone = "Integer"
Title = "Text"
TreeViewEnabled = "Text"
UIVersionConfigurationEnabled = "TRUE" | "FALSE">

The easiest way to create a WebTemplate feature using Visual Studio is to design the site
in the browser. Then you can save it as a template and export the resulting .WSP package
file, downloading it from the Solution Gallery page of the Site Collection. From there, you
simply need to import the .WSP into Visual Studio, creating a new project of type “Import
SharePoint Solution Package.”

WebTemplate feature has been implemented by Microsoft specifically to satisfy the requirement of deploying web templates through sandboxed solutions.

To customize the web template project, you can manually open the imported ONET.XML file
and change its contents.


No comments:

Post a Comment