If you are already familiar with site definitions in 12 hive, you must be aware that the WEBTEMP*.xml files in 12 hive contain the site definition configurations and these templates show up (depending on parameters like Hidden, RootWebOnly, SubWebOnly etc.) in template selection section when you create a new site. Usually each template that is listed here will have a folder in “site templates” directory with the name as specified in the Template Name attribute. For e.g. STS, MPS folders in SiteTemplates directory. But there are some templates which do not have these corresponding folders in SiteTemplates directory. E.g., Collaboration Portal (SPSPORTAL) and Publishing Portal (BLANKINTERNETCONTAINER) in webtempsps.xml file and Records Center (OFFILE) in webtempoffile.xml file which are few OOTB site templates in MOSS. So how does SharePoint handle these sites? SharePoint gives you the ability to add your custom code and have your own implementation during site creation. So now you can write custom code that you want to apply during site creation. This is known as Site Provisioning and these sites are provisioned via SPWebProvisioningProvider. Have a look at the configuration parameters listed below along with its definition, as defined in SDK.
- ProvisionAssembly: Gets the name of an assembly that provides logic for sites created through the site definition configuration or site template.
- ProvisionClass: Gets the name of a class that provides logic for sites created through the site definition configuration or site template. This class should inherit from SPWebProvisioningProvider and should have overridden Provision () method.
- ProvisionData: Specifies custom data to pass to the site provisioning handler for creating sites.
So ProvisionAssembly and ProvisionClass attributes tell SharePoint which assembly and which class contains logic. Now, if you have a look at configurations of above mentioned templates Collaboration Portal (SPSPORTAL), Publishing Portal (BLANKINTERNETCONTAINER) and Records Center (OFFILE), you will see that each of these configuration contain the attributes ProvisionAssembly, ProvisionClass and ProvisionData. Take for example Publishing Portal (BLANKINTERNETCONTAINER). This template configuration has: ProvisionAssembly="Microsoft.SharePoint.Publishing, Version=22.214.171.124, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ProvisionClass="Microsoft.SharePoint.Publishing.PortalProvisioningProvider" ProvisionData="xml\InternetBlank.xml" Here the class Microsoft.SharePoint.Publishing.PortalProvisioningProvider inherits from SPWebProvisioningProvider. Let’s have a look via reflector.
So let’s see how SharePoint actually handles this. But before that, let’s just have a look at the custom configuration file specified in ProvisionData attribute. Open the xml file “InternetBlank.xml” which is located in folder
“C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions12TEMPLATEXML”.
Here, a root web of type “BLANKINTERNET#0” is specified along with its child webs “PressReleases” and “Search” of template type “BLANKINTERNET#1” and “SRCHCENTERLITE#1” respectively. So ultimately, the site provisioning should end up creating a parent web and two child webs. Now let’s start peaking through SPWeb.ApplyWebTemplate(string) method using reflector. Here, you will see there’s specific logic implemented here for template configurations with ProvisionAssembly and ProvisionClass attributes defined. For those templates, DoProvisioningCallback is calledwith necessary provisioning parameters.
This method will create an instance of PortalProvisioningProvider of type SPWebProvisioningProvider, which in our case would be Microsoft.SharePoint.Publishing.PortalProvisioningProvider, specified by sProvisionAssembly parameter.
Then it calls overridden implementation of Provision () method of PortalProvisioningProvider.
Navigate to CreatePortal(xmlfile,web) method. Here, it will first load the xmlfile file “InternetBlank.xml” and then try to apply the settings as specified in this configuration.
You will see that it will first try to apply the template of the root web which is BLANKINTERNET#0 (indicated in red box in figure above), specified by siteDefinition attribute in “InternetBlank.xml” settings file. It will set its Title, DisplayName and it Description. Then it will proceed towards any child webs specified in this file, which is PressReleases and Search in our case. This is handled by CreateChildWebs() method as shown below.
So you can also write your own implementation by inheriting from SPWebProvisioningProvider and setting up necessary configurations and code behind. Or if you want something like a number of sub sites (like blog, wiki, team site) to be created automatically when user tries to create a specific site, then this can be achieved easily by having similar implementation to that of PortalProvisioningProvider or by using PortalProvisioningProvider itself and specifying the sites and sub sites to create in the xml configuration file.