I have created a webtemplate feature based on TeamSite project, but I want to add code to run when I create a site based on this template.
Any idea how to do this?
Thanks in advance for your help.
|
I have created a webtemplate feature based on TeamSite project, but I want to add code to run when I create a site based on this template. Any idea how to do this? Thanks in advance for your help. |
||||
|
|
|
Since we are talking SharePoint 2010 I would recommend using the WebProvisioned asynchronous event. This event is triggered when a subweb under your rootweb is created (note that it does not trigger when creating root site, if you need this, consider either feature stapling as Jeroen suggests, or a custom provisioning provider (CPP) as Charles suggests). Each approach has its advantages, one of the reasons why I often for site provisioning prefer provisioning providers over feature stapling is race conditions. In short you cannot be sure when your feature is called if you have other stapled features in the same scope. In SP2010 i tend to use CPP for site provisioning where i need code to execute for root site, and WebProvisioned event for everything else. |
|||
|
|
|
Your question is rather vague but I think what you are looking for is an implementation of SPWebProvisioningProvider. This is a class that can execute custom code when a new site is created. More information can be seen here: |
|||
|
|
You may want to consider Feature Stapling. |
|||
|
|