locked
FeatureActivated event not fired. RRS feed

  • Question

  • I created a feature and include the feature in a custom site definition. The feature contains some custom logic in the FeatureActivated event handler, which is fired every time a site (SPWeb) is created based on the custom site definition. So far so good. I then saved the site as a custom site template and created another site based on the custom site template. The FeatureActivated event handler was not fired although the feature is shown as active through the "site settings > site features" UI.Does anyone else have this problem? How else I can execute some logic whenever a site is created?

    Thanks.
    Tuesday, May 13, 2008 5:08 PM

Answers

  • as per my understanding FeatureActivated runs only once. if you create a new SPWEB , feature will be shown as Active on that site level but its featureactivated will not run. You will need to deactivate and activate feature again in order to apply this to your new site.

     

    there are events available for SPWeb object but they are for Deletion and Move kind of events

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebeventreceiver_members.aspx

     

    Tuesday, May 13, 2008 7:41 PM
  • You will have to create a custom site definition that has it's own SPWebProvisioner.  There is a Provision method that you override.  This method gets called once the site has been created.  Inside your overridden Provision method you would check for the Feature and then Activate it accordingly.  Look in the WSS SDK for SPWebProvisioningProvider or you can go here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebprovisioningprovider.aspx.  There are a lot of blogs out there on how to create Site Definitions.

     

    HTH.

    Tuesday, May 13, 2008 7:41 PM

All replies

  • as per my understanding FeatureActivated runs only once. if you create a new SPWEB , feature will be shown as Active on that site level but its featureactivated will not run. You will need to deactivate and activate feature again in order to apply this to your new site.

     

    there are events available for SPWeb object but they are for Deletion and Move kind of events

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebeventreceiver_members.aspx

     

    Tuesday, May 13, 2008 7:41 PM
  • You will have to create a custom site definition that has it's own SPWebProvisioner.  There is a Provision method that you override.  This method gets called once the site has been created.  Inside your overridden Provision method you would check for the Feature and then Activate it accordingly.  Look in the WSS SDK for SPWebProvisioningProvider or you can go here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebprovisioningprovider.aspx.  There are a lot of blogs out there on how to create Site Definitions.

     

    HTH.

    Tuesday, May 13, 2008 7:41 PM