Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

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.

share|improve this answer
add comment

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:

http://blogs.technet.com/b/apurdon/archive/2008/02/05/the-mystery-that-is-spwebprovisioningprovider.aspx

share|improve this answer
    
Dear Sir, I am working on Visual Studio 2010 and SharePoint 2010. I want to create a Site Template based on TeamSite template. So I created a webtemplate feature, but I want to run code in site provisioning –  user2180 Feb 9 '11 at 13:24
add comment

You may want to consider Feature Stapling.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.