Best Practice
We've covered several different approaches to creating templated SharePoint Sites, now I'll bring everything together and we can walk through what I would recommend as a best practice.
Goals
First let's talk through my goals. You may find that our goals differ and, in that case, one of the approaches on my previous post would work fine in your scenario.
- Allow Site Administrators to create a site using the out of the box site creation screens
- Support Feature Stapling for future updates
- Create no dependencies on the SharePoint Farm:
- The Site "Template" can be removed at any time without affecting previously created sites
- Minimal impact projected during future platform upgrades
Almost There
At first glance we can get pretty close using the Feature Stapling approach outlined in my previous post. The biggest barrier is the creation of a new Site Definition which we have identified as an unacceptable dependency. If we want to use Feature Stapling, we need a unique Template Name to point to... If we create a unique Template Name, we have a dependency...
The Keystone
The piece that makes it all possible: SPWebProvisioningProvider. A Provisioning Provider can be specified in a Site Definition's webtemp*.xml file. In the configuration element, you can specify the ProvisionAssembly, ProvisionClass, and ProvisionData attributes.
Hold it right there, does that mean we're creating a Site Definition? I thought they were the root of all evil? Not so fast, my friend:
If you implement your own class that inherits from SPWebProvisioningProvider, you can use it to call the ApplyWebTemplate method of a Web which allows you to manually provision one of the out of the box Site Definitions! That means you get your unique Site Template Name but when the site is created it THINKS it is an out of the box Site Definition!
As my buddy Tom used to say, NOW how much would you pay? :-)
The Solution
- Create the webtemp*.xml (using the ProvisionAssembly and ProvisionClass attributes):
- Create the Provisioning Provider (which applies the "Blank Site" Site Definition):

- Create any Feature Receivers and Feature Staplers
- Wrap everything into a SharePoint Solution and you're done!
Post-Deployment you can make updates by updating your Feature Receiver or the code in your provisioning provider. Also, if you're done making sites of that type, go ahead and uninstall your SharePoint Solution: Your sites were created using out of the box Site Definitions so there is no leftover dependency.
Conclusion
This series of posts covers a lot of information and skims over even more. I intend for it to be an evolving series and will be adding code samples and follow-up posts. For the latest, keep an eye on the series introduction or subscribe to this post's category.