Site Template vs Site Definition

Site Definitions

  • A site definition is the core definition of what a site is in SharePoint.
  • A site definition is installed on file system of web front ends, located at ..12TemplateSiteTemplates. This directory is language-neutral.
  • A site definition consists of .aspx pages and .xml files with Collaborative Application Mark-up Language (CAML).
  • A major benefit is that the Page and List definition is read locally from the file system, not from Content Database.

Site Template

  • A site template (*.stp file) is created through the user interface or through implementation of the object model.
  • The site template package is a package containing a set of differences and changes from a base site definition.
  • The site template package is stored as a CAB-based file that can be downloaded or uploaded to site collections by users with the appropriate rights. 

When choosing whether to create a site template or a site definition, first consider the following issues:
Are the changes you need to make simple or complex? If, for example, you need to make only minor changes in the look of certain pages and add a few fields in particular lists, you should create a custom site template.
However, if you need to create new content types, add new Web Part definitions, and significantly restructure sites, you should create a custom site definition.
Can you deploy changes to the front-end Web server? If you do not have access to the file system of the computers running Windows SharePoint Services, you have no choice but to create a custom site template.

Site definition (Advantages):

  • Data is stored directly on the Web servers, so performance is typically better.
  • A higher level of list customization is possible through direct editing of a Schema.xml file.
  • Certain kinds of customization to sites or lists require use of site definitions, such as introducing new file types, defining view styles, or modifying the Edit menu.

Site definition (Disadvantages):

  • Customization of site definition requires more effort than creating custom templates.
  • Editing a site definition after it has been deployed is difficult.
  • Doing anything other than adding code can break existing sites.
  • Users cannot apply a SharePoint theme through a site definition.
  • Users cannot create two lists of the same type with different default content.
  • Customizing site definitions requires access to the file system of the front-end Web server.

Site Templates (Advantages):

  • Custom templates are easy to create.
  • Almost anything that can be done in the user interface can be preserved in the template.
  • Custom templates can be modified without affecting existing sites that have been created from the templates.
  • Custom templates are easy to deploy.

Site Templates (Disadvantages):

  • Custom templates are not created in a development environment.
  • Custom templates are less efficient in large-scale environments.
  • If the site definition on which the custom template is based does not exist on the front-end server or servers, the custom template does not work.

“Failure decompressing data from a cabinet file” error while saving a site as template

After you increase the size of site template using the following command

Stsadm.exe -o setproperty -pn max-template-document-size -pv 524288000 

to set the maximum template size to 500 MB. You might get an error “Failure decompressing data from a cabinet file”. It is a known issue from microsoft

Alternatively you can use import/export functionality of stsadm to serve your purpose

stsadm.exe -o export -url http://{yoursite} -includeusersecurity -nofilecompression -filename C:Mybackup

stsadm.exe -o import -url http://{yoursite} -includeusersecurity -nofilecompression -filename C:Mybackup

Create Site Template Pro-grammatically

We have many a time saved a SharePoint site template using the SharePoint User Interface. But did you know that we can save the site template pro-grammatically as well. Let me tell you how…

using(SPSite siteCollection = new SPSite("http://{yoursite}"))
  using(SPWeb web = siteCollection.RootWeb)
    web.SaveAsTemplate("TemplateFileName.stp", "Template Title", "Template Description.", true);