Deploy templates (SharePoint Foundation 2010)

 

Applies to: SharePoint Foundation 2010

This article describes how to create a custom site definition and deploy it by using a solution package.

In this article:

  • What are site definitions?

  • Site definitions and configurations

  • Create a custom site definition and configuration

  • Deploy a site definition by using a solution package

What are site definitions?

In Microsoft SharePoint Foundation 2010, a user creates a site through the user interface (UI) by selecting a site definition configuration or custom site template that defines how to instantiate the site. A site definition is a template that determines, for example, the lists, files, Web Parts, Features, or settings with which to provision a new SharePoint site.

A site definition is a family of site definition configurations. Each site definition specifies a name and contains a list of the site definition configurations. In SharePoint Foundation 2010, a site definition consists of a set of XML files that can be applied to provision new sites. The files are located on Web servers.

Site definitions consist primarily of multiple XML and ASPX files stored on a front-end Web server in folders under the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates folder.

A site created from a site definition adds to, but does not repeat, the structural and content information from the original site definition. Throughout their lifecycle, sites continue to depend on the site definition that is their ultimate foundation. For this reason, Microsoft does not support changing or removing a site definition after sites have been created from it. Such changes may cause sites created from the definition to stop working properly or may prevent the creation of new sites based directly, or indirectly, on the site definition. To customize a site definition, developers can add a Feature that includes the changes to the site definition. The site definition itself is not modified.

For more information about what kinds of customizations of site definitions are supported by Microsoft, see Supported and unsupported scenarios for working with custom site definitions and custom area definitions in Windows SharePoint Services, in SharePoint Portal Server 2003, and in Office SharePoint Server 2007 (https://go.microsoft.com/fwlink/p/?LinkId=187678).

In the object model, an SPWebTemplate represents a site definition (and configuration). For more information about site templates and site definitions, see Site Templates and Definitions (https://go.microsoft.com/fwlink/p/?LinkID=184756).

Note

The STP format of a custom site template (.stp file) is deprecated in SharePoint Foundation 2010 and replaced with WSP format site templates. In Windows SharePoint Services 3.0, users can save an existing site as a custom site template. The site template is stored in the database as a model, and users can select the site template as a foundation that defines how to instantiate the site. In SharePoint Foundation 2010, users can save an existing site as a template. The template is saved as a .wsp file in the Solution Gallery of the top-level site in a site collection, where it becomes available for subsite creation on all Web sites in the site collection..

For more information about site definitions, see Site Definitions and Configurations (https://go.microsoft.com/fwlink/p/?LinkId=183458).

Site definitions and configurations

A site definition defines a specific SharePoint site. There are five site definitions natively installed in SharePoint Foundation 2010. A site definition can include more than one site definition configuration. SharePoint Web sites are based on specific site definition configurations that include the following:

  • STS includes the site definition configurations for Team Site, Blank Site, and Document Workspace.

  • MPS includes the site definition configurations for Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, and Multipage Meeting Workspace.

  • CENTRALADMIN provides a site definition configuration for Central Administration Web sites.

  • WIKI provides a site definition configuration for Web sites that support community content by using wiki technology.

  • BLOG provides a site definition configuration for blogs.

Each site definition consists of files that are placed in the \\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates subfolders of front-end Web servers during installation of SharePoint Foundation 2010. Site definition files include .xml, .aspx, .ascx, and .master page files, in addition to document template files — such as .dot and .htm — and content files, such as .gif and .doc.

Uncustomized pages and page customization

Site definition files are cached in memory on the server at process startup of Microsoft Internet Information Services (IIS). This allows uncustomized pages to be reused across sites. The information contained in these files is pulled from the cache at run time. Pages and list schemas are read from the site definition files but appear to be actual files within a site. New Web Part pages are also considered to be uncustomized.

When site pages are customized — excluding browser-based customizations such as modifications to Web Parts — their contents are stored in the content database, and the customized site page is used instead of the original page from the site definition. Uploaded .aspx files are automatically considered to be customized.

For more information about ghosting and page customization, see Site Definitions and Configurations (https://go.microsoft.com/fwlink/p/?LinkId=183458).

Core schema files

The following table lists the core XML files that can be modified for a site definition and shows their locations in the file system.

WebTemp.xml

Identifies the site definitions and provides information about their configurations. Located in:

\TEMPLATE\1033\XML

Onet.xml

Defines the navigation areas, specifies the list definitions available, specifies document templates and their files, defines the base types for lists, and defines configurations and modules for site definitions. Located in:

\TEMPLATE\SiteDefinitions\site_type\XML

Schema.xml

Defines the views, forms, toolbar, and special fields in a list definition. Each definition has its own Schema.xml file. Located in:

\TEMPLATE\FEATURES\List_Definition_Name

DocIcon.xml

Each front-end Web server in a SharePoint Foundation deployment contains a DocIcon.xml file that maps file programmatic identifiers (ProgIDs) and file name extensions of document types to specific icons and to controls for opening each type. Changes to DocIcon.xml are global to a SharePoint Foundation deployment and affect all site definitions on the front-end Web server. Located in:

\TEMPLATE\XML

These XML files use Collaborative Application Markup Language (CAML) (https://go.microsoft.com/fwlink/p/?LinkID=183464) for defining aspects of a site. For more information about these core XML files that you can use to customize site definitions, see Site Definitions and Configurations (https://go.microsoft.com/fwlink/p/?LinkID=183458).

Create a custom site definition and configuration

You can create custom site definitions by manually copying an existing site definition or by importing a .wsp file into Visual Studio 2010.

Import items from an existing SharePoint site

This method requires saving a site as a template from SharePoint Foundation to generate a .wsp file, and then importing the .wsp file into Visual Studio 2010 by using the solution import project template. The Import SharePoint Solution Package project template lets you reuse elements such as content types, list definitions, and fields from existing SharePoint sites in a new Visual Studio SharePoint solution. For more information about importing items from an existing SharePoint site into a Visual Studio SharePoint project, see Importing Items from an Existing SharePoint Site (https://go.microsoft.com/fwlink/p/?LinkID=187040). This chapter includes a walkthrough that demonstrates the following tasks:

  1. Customizing a SharePoint site by adding a custom site column.

  2. Exporting a SharePoint site to a .wsp file.

  3. Importing the .wsp file into Visual Studio SharePoint project by using the .wsp Import project.

Copy an existing SharePoint site

This method involves copying an existing site definition, modifying the copy, and changing two schema files: the copy of a WebTemp.xml file, and the copy of an Onet.xml file.

Warning

Do not modify the originally installed WebTemp.xml file.

  1. Copy an existing site definition folder located in the Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates\ directory. Your copy should be a peer of the original, and you can give it any name that contains no spaces.

    For example, to create a custom site definition that derives from the team site definition for Microsoft SharePoint Foundation, copy the \sts folder.

  2. Make a copy of the WebTemp.xml file. This file is located in Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\1033\XML.

    Give the file a unique name by appending a string to the name of the original file; for example, WebTempAction.xml. At run time, the compiler merges information contained in this file with the information contained in the original file to specify which site definition configurations are available for creating new sites.

  3. Customize the contents of the new WebTemp file.

    Each WebTemp.xml file contains a collection of Template elements and Configuration subelements, which identify to the compiler all the site definition configurations that can be instantiated. The Configuration element defines, for example, a title, a description, the URL for the image displayed in the user interface (UI), and a display category that specifies the tab on which to display the template in the Template Selection section of the Create Site Collection page.

    Important

    In each Template element defined in the WebTemp file, the Name attribute must contain the same name that is assigned to the new folder.To avoid conflict with IDs already used in SharePoint Foundation 2010, use unique values greater than 10,000 for the ID attribute.

The following example uses two Configuration elements in the WebTemp.xml file to define different site definition configurations for instantiating a site, one for a Research Collaboration site and the other for a Research Document Workspace site. This example uses only two configurations within a single site definition, but you can include multiple site definitions, each with multiple configurations, within a single WebTemp.xml file. Each site definition references a different site definition folder and its Onet.xml file.

<?xml version="1.0" encoding="utf-8" ?>
<Templates xmlns:ows="Microsoft SharePoint">
  <Template Name="RESEARCH" ID="10001">
    <Configuration ID="0" Title="Research Collaboration site" 
      Hidden="FALSE" ImageUrl="_layouts/images/stsprev.jpg" 
      Description="This definition creates a site for the Research 
      team to create, organize, and share general information." 
      DisplayCategory="Collaboration">
    </Configuration>
    <Configuration ID="1" Title="Research Workspace" Hidden="FALSE" 
      ImageUrl="_layouts/images/dwsprev.jpg" Description="This 
      definition creates a site for Research team colleagues to 
      work together on specific documents." 
      DisplayCategory="Collaboration">
    </Configuration>
  </Template>
</Templates>

As indicated by the value of the Name attribute in the Template element, this example assumes that a site definition directory named "RESEARCH" exists. If a WebTemp*.xml file specifies more than one site definition, the definitions are distinguished by their unique ID values.

Each Configuration element also contains an ID attribute. The combination of this ID and the value of the Name attribute in the Template element provides a reference to the contents of a specific Configuration element in a specific Onet.xml file. In the example, the Name attribute contains RESEARCH and the ID attributes contain 0 and 1, which reference the RESEARCH site definition and configurations with IDs of 0 or 1 in Onet.xml.

You may need to reset IIS to cause the new definition configuration to appear as an option in the UI. To do this, enter iisreset at a command prompt.

For more information about defining each site definition configuration in Onet.xml, see How to: Use Site Definition Configurations (https://go.microsoft.com/fwlink/p/?LinkId=183465).

Deploy a site definition by using a solution package

To deploy a custom site definition by using a solution package, add a SiteDefinitionManifest element to the manifest file of the solution package. Add the TemplateFiles element to define the template files that must be deployed in a subfolder of the \14\Template folder

Add a SiteDefinitionManifest element

The SiteDefinitionManifest element has a Location attribute that picks up all the files in the specified folder and creates the required folder in the \14\Template\SiteTemplates folder. The WebTempFile child element deploys the webtemp*.xml file to make the template known to SharePoint 2010 Products, as shown in the following example:

  <SiteDefinitionManifests>
    <SiteDefinitionManifest Location="LitwareSiteTemplate">
      <WebTempFile Location="1033\xml\webtempLitware.xml" />
    </SiteDefinitionManifest>
  </SiteDefinitionManifests>

Add a TemplateFile element

The TemplateFile element in a solution manifest file is used to define the template files that must be deployed in a subfolder of the \14\Template folder. An example of the kind of file you can deploy in this way is the fldtypes*.xml file, which defines the details of a custom field type. Use the Location attribute to specify the relative path to the file, which is indicated by the string "Text" in the following example:

  <TemplateFiles
    <TemplateFile
      Location="Text"/>
      ...
  </TemplateFiles>

For more information about how to deploy solutions, see Deploy solution packages (SharePoint Foundation 2010).