I am using sp 2013. I have some custom code which is adding some webpart to the welcome page. I would like to execute this code for each new site collection depending on a template (mysites). Someone told me you can do that with a feature stapling or delegated control. Can someone tell me if it is possible with delegated control or feature stappling? And maybe how to implement this?

2 Answers 2


I think you create an event receiver scoped to Web Events and fire it when A Site is being provisioned and A site was provisioned.

enter image description here

How to Attach an Event Receiver to the Web Added Event And For What Purpose
How to: Programmatically Activate a Feature

  • Original question was about provisioning a "Site Collection" and not a "Site". This won't work. Apr 20, 2015 at 7:20
  • yes thats correct. I am talking about site collections.
    – Ola
    Apr 20, 2015 at 7:23
  • yes, you can use that method to check how many webs are there in the site collection. I suppose that u create a web after the site collection creation
    – Nk SP
    Apr 20, 2015 at 7:27
  • As per my knowlege, ' on site provisioning/ed' event recievers are site scope, that means they work for subsites of a site collection. I am sure, a logic can be implemented for the event reciever to be triggered on creation of the root level site ('/') of the site collection Apr 20, 2015 at 7:38
  • No, this won't work. aennen.wordpress.com/2013/11/14/… Feature stapling is the best approach here. Apr 20, 2015 at 7:44

It's not possible to create site collection scoped event receivers. What you need is "Feature Stapling".

You can connect a site or web scoped feature to a certain site template.

So in your case you create a site scoped feature that contains the code to manipulate the home page of the root web. If you also want to activate that kind of modifications on all newly created sub webs you should put that logic into a single web scoped feature.

So your site scoped feature not just changes the home pages but also attaches a "site created" event receiver to make sure that every sub web will get the correct homepage modifications.

After that you create a farm scoped or web application scoped feature which contains the feature stapling XML element with a GLOBAL entry. Deploy that and activate it on the farm / web application. The feature stapling will be active then and will activate your site scoped feature on every newly created site collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.