Creating custom site definitions are now a thing of the past. Microsoft now recommends using the component "Site Provisioning Provider" as best practice for providing a custom site template. This is not new and was also available WSS3.0 but instead of creating a custom site definition, we add custom provsioning code to the out-of-the-box site template.

Step One:

Fire up Visual Studio 2010 and create new project using the "Empty SharePoint Project".

Step Two:

Before you start working on your new project, open the properties page and on the "Application" tab, make sure that the target framework is set to ".Net Framework 3.5". SharePoint 2010 is not using .Net Framework 4.0.



Then select the "Build" tab and by default the platform target will be set to "Any CPU". Change this to x64. Just do it!




Step Three:

Right click the solution name and choose "Add" and right click "SharePoint Mapped Folder". We want to map the SharePoint root so click the very top "SharePointRoot" The solution explorer should now like this:




Step Four: Now add the following folder structure underneath your sharepoint root like this:





Step Five: Next, add an XML file underneath the XML folder like so:





The XML will contain the following provisioning instructions and it will look like this:





Step Six: Next, add a Class file and give it a name. This is your "Provisioning Provider". Add the Microsoft.SharePoint referrence and if you're a newbie, you'll find it underneath the "ISAPI" folder underneath the SharePoint "Root". What was it called in MOSS2007? The 12 Hives folder, but for SharePoint 2010 it's now called the "SharePoint Root". In Ted Pattison's "The Great SharePoint Adventure 2010"  development training course, we were told that the new SharePoint product team changed it to "SharePoint Root". Nonetheless, I've noticed that some are referring to it as the 14 hives.  Also make sure the Microsoft.SharePoint.Security referrence is also added. Build your project here. Or you can wait until you've added the code. I've gotten into the habbit of buidling my projects often, even for SharePoint.


Look at the top line. You are inheriting from the SPWebProvisioningProvider base class and overriding virtual methods to create your own Site Template Provisioning Provider.





You're actually overriding the "Provision" method of the Provisioning Provider base class. When you implement this virutal method, you can now specify custom configuraton properties by calling the "ApplyWebTemplate" method. This makes it possible to customize out-of-the-box site templates with our own customized provisioning instructions. Very cool!

During the execution of code, the out-of-the-box site template is created through the "ApplyWebTemplate" method using the "Blank Site" template "STS#1". The rest of the code is added to provide the required site elements for the custom site template.





Again, build your solution. Then deploy it like this:





Your Done!

 



After deploying your solution and no errors are reported, you can check your new category and templates using several different ways. First, if you have "Self-Service Site Creation" enabled, and I hope you don't, you can click the link "Self-Service Site Creation" under "Annoucements" on the home page.





Then click the "http://your site/_layouts/scsignup.aspx" link and you will navigate to the following page.





As you can see, the category "JTWebNet" is listed, and underneath this category are the "JTWebNet Standard Team Site" and "JTWebNet Consultant Site" templates. You don't see an image for either template because I haven't added one to the layouts/images/jtwebnet/ folder. I chose the "JTWebNet Consultant Site" template for my first custom templated site. After SharePoint provisions the site by default your taken to the SharePoint security groups setup page where you specify which Active Directory groups are to be used. As you can see the site owner/administrator is already plugged into both the member/contributors and admin groups. After you setup your SharePoint security groups you are now ready to start customizing your new site with web parts and content.





Very easy to implement and provides a professional looking custom site template for your client. Now you can take it a step further by deleting the other categories thereby eliminating the option for creating out-of-the-box site templates. Go to site settings and click on the "page layouts and site templates" link and set the following:





If the site owner/administrator decides to create a subsite, there is only one category diplayed and only those custom template options will be available. For the farm administrator that is a different story. Although I may have always provided that customization with a custom site definition, I will not show you how to delete those categories with this solution.

 

 

 

Before I move on to feature stapling, I think I will post the branding solution first.