Friday 5 September 2008

Creating Custom Meeting Workspaces Site Definitions

My college was working on a project that needed to create a custom Meeting Workspace site definition.

The simple answer would be to create a copy of the site definition and work from there
However as quite often SharePoint is not quite so simple.

The problem comes in the form of 3 web parts embedded in the MasterPage. These web parts check to see that the webTemplateId of the current SPWeb object is equal to 2 (which is the ID of the MPS templates In the webtemp.xml). These web parts then fail to render breaking the site.

He had located the problem but was unable to find a acceptable workaround.
1) He could modify the OotB MPS Site Definition (This is NOT acceptable practice)
2) He could use a feature stapler to modify the Site Definition on creation(This would apply to all new Meeting Workspace across the Farm and not really practical given the project)
3) he could remove the Web Parts and replace them with custom ones (the classic developer answer but never a practical one)

None of these option were really viable for his project.

So I asked him if he had thought of using a SPWebProvisioningProvider class.
With a little testing we found that the SPWebProvisioningProvider does not change the WebTemplateID as the Site Definition used during the provisioning of the site is still the OotB MPS Definition and the Provisioner runs code After the site had been created.

He can now create a Customised Meeting Workspace site definition.
the SPWebProvisioningProvider class he is using is quite small as all it does is activate and deactivate a few features, this allows for easy modification of the features rather than having to recompile the provisioner should the client wish to change anything.

Just something that popped up today :)

1 comment:

John Vivian said...

We dident create a new Site Definition defined in CAML but just a provisioning provider that provisions a site based on the Out of the box MPS site definition and then triggerd a custom feature which in turn called all of our feature that were created in our original ONET.xml attempt.

We created a SPWebProvisioningProvider class and created the relevant WEBTEMP*.xml that refrances it.

Inside the SPWebProvisioningProvider Class you need to call the web.ApplyWebTemplate("MPS#0") where #0 is the id of type of Type of Meeting Workspace (See the File in 12\Template\{Lcid}\XML\WebTemp.xml for the diffrent Template IDs), This then provisions a site using the Ootb "MPS#0" Site Definition (which has the webTemplateId ste to 2) when you call the web.Update() method.

Once the Site has been provisioned we get a new SPWeb object as the original one has had its Update method called and canot be modfyed.

You can now make our changes to the site to customise it.

We simply actvated a feature and did the heavy lifting in that feature dependancies.

Hope this helps , I will try make some time to write a post on the SPWebProvisioningProvider and what it actualy does, 90% of the time you never need one as it is reliant on a normal ONET.xml based Site Definition. You could look at is as a WebAdding + WebAdded event or evan as a kind of Feature Stapler that runs code.

The Best Ootb Example of one the the MOSS Publishing site definition.

Hope this helps a bit