As you might know, Site Definitions are not supported on Office365. This is not a restriction of Office365 as such, but more a Sandboxing restriction. In a SharePoint 2010 Sandboxed environment you’re not allowed to deploy files to the file system. And a SharePoint Site Definition requires that.
The answer lies in the newly introduced web template tag. In this post I will describe, step by step, how to create a web template, and how to create a new Site Collection based on that web template.
So, if I have create a Web Template instead of a Site Definition, what is the problem?
Office365 is a sandboxed environment. That means that if you create a web template, and you packaged it nicely in a WSP file, you can upload that WSP to the solutions gallery of your site collection and activate it. After activation you have a template available to create the site from. And there we have a catch-22. What if the site we upload the solution package to, so the site itself, needs to be based on a webtemplate? In a on premise environment, where you are farm administrator, you simply upload the package to your farm, activate a feature on WebApplication level that installs the template and of you go. But that level of access you don’t have in Office365 or any other Sandboxed environment.
- Create a new SharePoint project (I picked a empty one for this example).
- Enter a url of a site on your local server.
When asked for the trust level, pick “Deploy as a sandboxed solution”.
- Add a new Empty Element to your project
- IMPORTANT: The name of the element should be *IDENTICAL* to the name of the Web Template you’re creating.
- You will end up with an empty “elements.xml” file in your editor.
- Create a new WebTemplate entry as follows:
<?xml version="1.0" encoding="utf-8"?>
Description="Company Root Site Template"
- Notice the Name property of the tag. That name should be identical to the name you used for the element in step 4.
- The BaseTemplateID is the ID of the Out of the box site definition. You can find those definitions in
If you have additional language packs installed on your server, like for instance Swedish, then there are other folders.
- Open the WEBTEMP.XML file and find the site definition you want to base your webtemplate upon. I picked the Blank site definition (STS), and that definition has an ID of 1. Set that value of the BaseTemplateID property.
- The BaseConfigurationID property is the configuration you want to use . The configuration and what is performed in it can be found in
- Provide values for the other properties as appropriate and you are almost done.
- If you want to use an ONET.XML file, you can. Copy an existing onet.xml file (or, if you want/can, create a new one from scratch) and add it to your newly created element. Mark the file as an ElementFile, as in the screenshot below:
- As Visual Studio automatically created a feature for you and added this elements file to the feature, its now just a matter of packaging your solution and you’re ready to deploy it to Office365.
Now, in order to use this newly created webtemplate for a new Site Collection, act as follows:
- Log on as administrator of Office365 and create a new site collection. When asked for the template, switch to the custom tab and pick “<Select template later…>”
- Wait until the site is created and click on the link to browse to it. You will be asked to pick a template. Do not pick the template, but go to the Site Settings by opening
- Open the solutions gallery, upload your solution package (WSP file) to the gallery and activate it.
- Now browse again normally to your site, and again you will asked to pick a template. And now, finally, your template will be available for selection. Pick it and your site will be created just the way you want it.