Friday 12 April 2013

Creating a SharePoint 2010 Site collection template

To create a site template which is available to choose when creating a site collection within Central Administration there is a number of steps you need to follow.

I have recently done this on a project, and had a few issues because I based my template on the out of the box Records Centre template (Enterprise template).

This post starts from the beginning, but also covers the additional steps you may have to cover if you are not starting with a blank site template in SharePoint 2010.

Within SharePoint create a site collection, once you are happy and wish to use that as your new template open SharePoint Designer 2010.

Open the site collection you wish to save as a template.



Use the 'Save as Template' button.

Give your template a meaningfull name and description.




To retrieve your exported template you will need to open the site collection in the browser.

Site actions > Site settings > Solutions




Download the 'wsp' file, you will need to browse to it in the next step.

Open Visual Studio and create a new project.





Select 'Import SharePoint 2010 Solution Package'.



Name your Project, be aware of the character limit when selecting the location of your project as the default location does not leave you many characters left to name the project.

I use a projects folder in 'My Documents' rather than nested another two levels below.




Choose to deploy as a farm solution.





Now browse to the 'wsp' file that was saved from SharePoint Designer.




You want to import all items to the project.





Now the project has been created open the solution explorer.






Rename your features so you can easily distinguish them apart.

The template is contained in Feature3.




Double click the feature to open the feature, set the Title and Description. These are used within the SharePoint UI when viewing the feature list.

I set all features except for Feature3 as hidden so this is no so important for them, but Feature3 will be visible so set this appropriately.

Set the Scope of Feature3 to Farm.

As highlighted above, click on the 'Files' link and open the  'Elements.xml'.

Within the elements file add a display category, this will be the tab in which the template will be displayed when creating a new site collection.





 Also set the 'subweb' attribute to 'TRUE'




Double click on each feature to view the properties.

Set all features except for Feature3 to be hidden.




If you based your template on a blank site template then you can now deploy your solution to SharePoint.

You can use the deploy option in Visual Studio or deploy via PowerShell which I will cover further on in this post.





As I based my template in the Records Centre template, there are 'Feature Activation Dependencies' which must be removed before being deployed.

Remove all dependencies.

These may vary depending on which template you based your own template on.

In the same way we opened the 'Elements.xml' file above, this time open the 'ONet.xml' file for Feature3.





'ThemedCssFolderUrl' must be set or removed, as all of my branding and CSS will be appplied via features I chose to remove this attribute.

When using the Records Centre, some attributes have been set which gives me an error when deploying this template as a farm scoped feature.

'UIVersion' also gave me an error when deploying through Visual Studio so I have removed this and will use powershell to set this later. This can be an issue and I intend to test if this is also an issue when starting with a blank site template. I will post an update on this.






To save the solution to a 'wsp' file to be deployed via PowerShell use the Publish option.

Save the 'wsp', in my example PowerShell below I have saved the 'wsp' to the root of the C drive.

Run the below PowerShell to add and deploy the solution to Ceentral Administration.

Add-SPSolution "C:\RecordsCentreTemplate.wsp"

Install-SPSolution -Identity RecordsCentreTemplate.wsp


If you now view farm features within Central Administration your feature should be visible.



Once activated you will be able to create new site collections from your template.




Hope this helps!

Matt


2 comments:

  1. Hi Matt,

    Nice post ,Thanks for sharing this post with snapshots.




    Sharepoint Developers

    ReplyDelete
  2. really nice

    Here in this case this will be site definition right.

    ReplyDelete