Friday, January 2

Overview of Custom Templates

Custom templates are created through the user interface or through the object model and are stored in the database, providing a means for reusing customized lists and sites. A custom template is a customization applied to a site definition. When a user customizes a site or list in the user interface, the custom template consists of the difference between the original state of the site or list as determined by its definition and the state of the site when the custom template is generated. Custom templates remain tied to a particular site definition (for example, the one for a SharePoint site or a Meeting Workspace site), so that if the site definition is not present or is changed, the custom template will not work.

A custom template is persisted as a file with .stp extension, which is actually a .cab file that can be renamed with the .cab file extension and opened in Windows Explorer. This file includes one Manifest.xml file in Collaborative Application Markup Language (CAML) that the server generates as a subset of the Microsoft SharePoint Migration Tool (Smigrate.exe) manifest file format.

[A cabinet (.cab) file is a library of compressed files stored as a single file. Cabinet files are used to organize installation files that are copied to the user's system. A large compressed file can be spread over several .cab files. Today, .cab files are used to reduce the file size and the associated download time for Web content that is found on the Internet or on corporate intranet servers.]
Custom templates include both list templates and site templates.

List templates:

List templates contain the files, views, fields, Web Parts, and, optionally, the content that is associated with a list. Users create list templates on the Save as Template page for a list or through code that uses the SaveAsTemplate method of the SPList class.

When saved, list templates are stored in the List Template Gallery of the top-level site in a site collection, where they become available to all sites in the site collection that derive from the same site definition and language as the site on which the list was originally created.

To make a list template available to a site in another site collection, download the template from its current gallery and then upload it to the gallery of the new site collection.

Site templates:
Site templates contain the same type of data as list templates, but site templates include data for the entire site. Like list templates, site templates may also include the content of the site. The maximum size for the content is 10 megabytes (MB). Users create site templates on the Save Site as Template page or through code that uses the SaveAsTemplate method of the SPWeb class.

When saved, site templates are stored in the Site Template Gallery of the top-level site in a site collection, where they become available for subsite creation on all sites in the site collection. Similarly to list templates, site templates can be downloaded and moved to other site collection galleries.

Unlike list templates, however, site templates can also be moved into the Central Site Template Gallery, where they become available for top-level site creation in Self-Service Site Creation in addition to subsite creation. To add a site template to the gallery from the command line, download the site template from the gallery, run stsadm.exe -o addtemplate -filename Template_File_Name -title Template_Title [-description Template_Description], and reset Internet Information Services (IIS). In code, use the AddCustomGlobalWebTemplate method of the SPGlobalAdmin class to add a site template to the gallery.

Site templates can include list templates. When a top-level site is saved as a template with content, it includes any list templates that are in the List Template Gallery for the site collection.