Friday, April 1, 2011

How to save a site template and use it is the farm to create site collections and sub sites in 2010

In 2007 when you wanted to create a new Site Collection with a template saved from a site, the site template needed to be installed globally before it could be utilized. The command to  do this are:

       // Add template to the global gallery so you could use any where
       stsadm -o addtemplate -filename Regions.stp -title Regions

      // You could check the template availability
      stsadm -o enumtemplates

Of case there are several major issues associated such as feature compatibility across environment and workflow will not working if save template with content. Of cause we have identified workarounds already last year to resolve those issues. I’m not a fun of site template and prefer to use site definition sue to the better maintainability.

SharePoint 2010 is little different and there are many ways to implement reusable templates.  To be specific using site template inn 2010, you can choose to load a site template to create sub sites or site collection at creation time. Here are two major use cases.

1.    The most user cases are using saved template as sandbox solution gallery in the solution to create sub site. The default wsp file saved is web scope and sandbox solution anyway. You could refer this blog on the procedure. It’s quite simple and I will not explain this in the blog.

2.    The second use case is users wants this template available to create site collection from site collection. In additional this template should be available globally to be provisioned by auto-provisioning tool such as SharePoint Site Provisioning and Governance Assistant (SPGA) tool we are using to automate the site creation and approval process.  In order to make it available in central admin when creating the site, there are some options and I’m listing the best option from our implementation to our end users. Again, as I mentioned before, I’m still prefer to use site definition unless we have to use site template sine it save some time.

There are several options to do this and some of them does not make sense to me and I was totally lost at beginning. You should avoid those if you need to use site template.

The first way to install template seems like to use powershell command Install-SPWebTemplate. Here are the procedure and issues.

   Command: Install-SPWebTemplate -path "E:/Harry/Temp1.wsp" -name "Temp1" -description "TestWSP" -Confirm:$false

    Error is : Cannot find or parse web template file E:/Harry/Temp1.wsp
    Result: You will not get template installed and I’m not sure what the usage of this powershell usage and could not figure out

The second way is to deploy the solution using  powershell command Add-SPSolution. Here are the procedure and issues.
   Commands:    Add-SPSolution -LiteralPath " E:/Harry/Temp1.wsp"
                            Install-SPSolution Temp1.wsp –GACDeployment

  Issue is :     Cannot find it from central admin to use for site collection creation
  Workaround:   You have to do some configuration to use it. See the blog for details.

The third way and I believe the best way inspired by the response from Mirjam’s response is to repackage the wsp using Visual Studio and deploy as farm solution. Here is the way to do this and you have much better control and maintainability. Here are the steps we implemented it.
  1. Create a new SharePoint 2010 project using Visual studio
  2. Selecting “Import SharePoint Solution Package” template
  3. Browse site template WSP file you want to use and select “Deploy this WSP as farm solution” – This is critical to make it available in the farm
  4. Select items you need as site template existed on this WSP to be packaged and click ok
  5. Change the web template feature scope from site to farm so that we can see this template on site collection creation page. Be aware of multiple features and you need to select the right one feature
  6. Add DisplayCategory="MyTemplate" on web template elements.xml file to include this template on your MyTemplate tab
  7. Package this solution and deploy the using Add-SPSolution
  8. Now open the Site collection create page, we can able to see “Temp1” template on MyTemplate tab as shown in below screen shot.

At this time, you should be able to use this site template to create new site collections or sub sites. However, there is potential issue that may prevent sites to be created successful - feature comparability. Unless you have exact same features installed on the farm as the site you saved as site template, you have have error feature not installed on the farm error when creating sites. I'll address this issue in later blog.

There is another issue on the sites created from such site template - the sites could NOT be backed up using Site Recycle Bin tool (Previous Site Deletion Capture) on SharePoint 2010 just discovered. I have described in the another blog


  1. Hi,

    I would like to exchange some in-depth consideration on this post. I'm having the same damn problem and I'm not coming out of it. Can we please exchange email? Mine is

    Best regards.