The solution Microsoft has provided is to create an event receiver called a Feature Receiver class for the feature. When tiggered, custom code can do any kind of setup, cleanup, or other job that might be required.
There are four events in the Feature life-cycle that can be triggered:
- FeatureInstalled
- FeatureUninstalling
- FeatureActivated
- FeatureDeactivating
- Create a strongly-named feature receiver assembly containing a class inheriting from SPFeatureReceiver
- Add custom code to the appropriate feature receiver methods
- Deploy the assembly to the GAC on the SharePoint server(s) where the feature is deployed
- Add a reference to the Feature Receiver assembly and class in the Feature.xml file
- Deploy the feature
The Microsoft SDK explains Features and feature receivers in detail. In the particular case that we ran into, Zac Smith has a great example explaining how to deprovision the web parts.
Hi ,
ReplyDeleteHow can we Dynamically register an event receiver for a feature event...using object model.
Thanks
Regards
Nimali
Hi Nimali, that's a good question. I've actually stayed away from using the SharePoint object model whenever possible for two reasons:
ReplyDelete1) The API wasn't well documented until recently
2) I've tried to focus on what could be done "out of the box", mostly be configuration.
So I can't answer this one off the top of my head. Let me try a little experiment and get back to you on the results.