Developing SharePoint Site Definitions

One of the advantages of using SharePoint for hosting websites is the ability to create additional sites based on templates. A site template contains a customization of a base site, and it has a .wsp extension. If the solution you want to implement consists of only a set of customizations (such as adding some libraries, lists, and so on), you could use a site template. However, the use of site templates might not always be the optimal solution when the need arises to create sites with similar or identical functionality. Site templates cannot contain custom Web Parts, workflows, events, or master pages; that is, SharePoint components that are based on custom files stored on the servers, and the site templates need to be used on a SharePoint installation where these files will not be distributed. This is where developing custom site definitions provide more benefits. A site definition includes the look and feel of the needed site as well as the core functionality of a SharePoint Foundation site.

Using site definitions also provides performance benefits over using site templates. Site definitions have the ability to be cached on the web server when first accessed at runtime. Each time a site is accessed that uses a site definition, the core information for this site is pulled from the cache for each request.

SharePoint Foundation comes with pre-installed site definitions, which are located on the web server in a subdirectory in the SharePoint root Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATESiteTemplates. Each site definition contains its own subdirectory under this folder. By default, this is the location for all of the out-of-the-box site definitions. This includes Team Sites, Blank Sites, Group Work Sites, and many of the other default site definitions.

One site definition is STS, which provides site templates for common sites, such as Team Sites, Blank Sites, and Document Workspaces. The other site definitions you’ll find in that folder provide templates for blogs, group work sites and meeting sites.

A site definition consists of a WEBTEMP.XML and the ONET.XML.

Exploring WEBTEMP.XML

When you first install SharePoint Foundation, a file named WEBTEMP.XML identifies each site definition, where Temp in this context means template, not temporary. It contains information pertaining to the site definitions and configurations for the site definition. It also determines how the site appears to users who are creating new sites. You can find this file at Program FilesCommon FilesMicrosoft Sharedweb server extensions14TEMPLATE1033XML, where 1033 is the current locale ID. A shortened version of this file is as follows:

<?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>
   </Template>
  <Template Name="STS" ID="1">
    <Configuration ID="0" Title="Team Site" Hidden="FALSE"
      ImageUrl="/_layouts/images/stts.png"
      Description="A site for teams to quickly organize, author, and share
        information. It provides a document library, and lists for managing
        announcements, calendar items, tasks, and discussions."
      DisplayCategory="Collaboration" >
    </Configuration>
    <Configuration ID="1" Title="Blank Site" Hidden="FALSE"
      ImageUrl="/_layouts/images/stbs.png"
      Description="A blank site for you to customize based on your requirements."
      DisplayCategory="Collaboration" AllowGlobalFeatureAssociations="False" >
    </Configuration>
    <Configuration ID="2" Title="Document Workspace" Hidden="FALSE"
      ImageUrl="/_layouts/images/stdw.png"
      Description="A site for colleagues to work together on a document. It
        provides a document library for storing the primary document and supporting
        files, a tasks list for assigning to-do items, and a links list for resources
        related to the document."
      DisplayCategory="Collaboration" >
    </Configuration>
  </Template>
. . .
</Templates>

Each <Template></Template> block identifies a set of similar site definitions. Each <Template> tag contains:

  • The Name attribute, which supplies a mnemonic name

  • The ID attribute, which supplies a unique identifier

Within each <Template></Template> block, there’s one <configuration> tag for each site definition, which contains:

  • The ID attributes, which provide a unique identity within each <Template> node.

  • The Title and Description fields, which specify values that the Template Selection page displays when a team member creates a site.

  • The Display category, which is the tab on which you want the name of the site to appear when you create a new site. You can specify one of the existing names (Collaboration or Meetings) or specify a new one.

  • Hidden, which determines whether the site should be shown to the users.

  • ImageURL, which is an image that will be shown when the configuration is selected.

Working with ONET.XML Files

Further information about each site definition appears in a file named ONET.XML. Because the WEBTEMP.XML file specified several template names (STS, MPS, Blog, Wiki, Central Administration), there are more than one ONET.XML files. To find these files, first browse to Program FilesCommon FilesMicrosoft SharedWeb server extensions14TEMPLATESiteTemplates, and then go to the following locations:

  • BlogXMLONET.XML

  • CENTRALADMINXMLONET.XML

  • MPSXMLONET.XML

  • sgsXMLONET.XML

  • stsXMLONET.XML

  • TenantAdminXMLONET.XML

  • WikiXMLONET.XML

Each ONET.XML file defines a series of common elements for individual sites to use. These include the following:

  • Navigation bars such as the Top Link Bar and the Quick Launch

  • Web-scoped and Site Collection–scoped features that are built into sites

  • Built-in Web Parts and pages

  • List templates

  • Document templates

  • Configurations

  • Modules

  • Footer sections used in server emails

Several types of tasks can be performed in ONET.XML to customize a site definition:

  • Specify an alternate CSS file, JavaScript file, or ASPX header file for a site definition.

  • Modify navigation areas for the home page and list pages.

  • Add a list definition as an option to the Create page.

  • Define a configuration for a site definition.

  • Specify the lists, modules, files, and Web Parts to be included when a site is instantiated.

SharePoint Foundation includes the global site definition file, which you can find at Program FilesCommon FilesMicrosoft Sharedweb server extensions14TEMPLATEGLOBALXMLONET.XML. This file contains provisioning information that can be used by every site definition such as base types, base master page, and so on. This file alleviates redundant data from being inserted into each ONET.XML file for each site definition. The following code snippet shows the base structure and elements that are included in the ONET.XML file:

<?xml version="1.0" encoding="utf-8"?>
<Project Title="Site Definition" Revision="1" ListDir=""
      xmlns:ows="Microsoft SharePoint">
   <NavBars/>
   <ListTemplates/>
   <DocumentTemplates/>
   <BaseTypes/>
   <Configurations>
...
      <Configuration ID="0" Name="Default">
         <Lists/>
         <Modules>
            <Module Name="Default" />
         </Modules>
         <SiteFeatures>
            <!-- BasicWebParts Feature -->
            <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
...
         </SiteFeatures>
         <WebFeatures>
            <!-TeamCollab Feature -->
            <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
...
         </WebFeatures>
      </Configuration>
...
   </Configurations>
   <Modules>
      <Module Name="Default" Url="" Path="">
         <File Url="default.aspx" NavBarHome="True" />
      </Module>
...
   </Modules>
   <Components>
      <FileDialogPostProcessor ID="BDEADEE4-C265-11d0-BCED-00A0C90AB50F" />
   </Components>
   <ServerEmailFooter>$Resources:ServerEmailFooter;</ServerEmailFooter>
</Project>

NavBars defines the top and side navigation bar. This node can contain additional NavBar elements, and the links can be added by using NavBarLink elements.

The ListTemplates section specifies the list definitions that are part of a site definition. The ListTemplate element also specifies a display name for the list definition and whether the option to add a link on the Quick Launch appears selected by default on the new page.

In addition, this element specifies the description of the list definition and the path to the image representing the list definition, which are both displayed on the Create page. This element is supported in SharePoint Foundation 2010 only for backward compatibility. If a list type needs to be defined, it needs to be defined as a Feature.

The DocumentTemplates elements describe what document templates will be used in document libraries.

The BaseTypes element of the global ONET.XML file is used during site or list creation to define the basic list types on which all list definitions in SharePoint Foundation are based. Each list template that is specified in the list templates section is identified with one of the base types: Generic List, Document Library, Discussion Forum, Vote or Survey, or Issues List. It is important to note that the BaseTypes section can only be implemented in the Global.XML file.

The Configurations element contains one or more configuration elements that contain the lists, modules, and Features that are created when the site definition is used to create a site.

The Components element specifies components to include in sites created through the definition.

The ServerEmailFooter element is used to determine the footer used in email sent from the server.

Creating a New Site Definition

Making changes to the default WEBTEMP.XML and ONET.XML files that come with Share-Point Foundation is not a best practice. The two main reasons are:

  • Microsoft considers these to be system files. As a result, any reinstallation, repair, or upgrade to SharePoint Foundation might replace them and overlay any changes you have made.

  • Any site created from a site definition continues to use the WEBTEMP.XML, ONET.XML, and schema.xml files indefinitely.

Therefore, an incorrect change, even if it works for new sites, could break hundreds or thousands of existing sites. Thus, the correct approach is to create new site definitions rather than change existing ones.

You can utilize Visual Studio to create a new site definition and package the site definition, which you can then deliver to a client. To create a site definition, use Visual Studio to create a Site Definition project, which automatically generates an ONET.XML, WEBTEMP*.XML, and default.aspx files. These files can be modified to include the configuration needed for your custom site definition. You can deploy the Site Definition project to your debug site and test your solution.

If there is a site definition that already exists from the out-of-the-box site definitions that closely resembles your needed solution, you can use a copy of those files as a template from which to create your custom site definition. This will save time as you will not need to create the entire solution from scratch.

Feature Stapling

When working with site definitions, you might want to add an additional Feature to a site definition, but don’t want to modify the site definition files themselves. This is sometimes the case when you want to extend the functionality of an out-of-the-box site definition in SharePoint. This can be accomplished by utilizing a concept called Feature Stapling.

Feature stapling is accomplished by creating a new Feature that references one or more existing site definitions by utilizing a FeatureSiteTemplateAssociation element. This element defines the association between the new feature and existing site definitions so that the associated Features will be automatically activated.

One of the new improvements to SharePoint 2010 that makes the stapling process easier is the implementation of new out-of-the-box event receivers. The event receivers that are beneficial to Feature Stapling are the web events that capture when a site is being provisioned and when a site has been provisioned.

A good example of how these events can be used is when you need to manipulate a list that is associated with a site definition after a site is provisioned. Previously, developers would use the FeatureActivated event and place some type of custom check and delay the activation process to make sure that any changes to the list occurred once the entire site was provisioned. This was required because by default the FeatureActivated event would fire before the list you needed to manipulate was created. If you did not provide the custom check, in many instances a System.Argument exception occurred, letting you know that list did not exist. Now with SharePoint 2010, you can accurately capture events after a site has been provisioned and then make the needed changes to the list without delaying the activation process.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset