In this first article I want to share the way that we can create a feature in Sharepoint 2007 and to develop the events fired when it’s installed. To create this project I’m using the last version of WSPBuilder from Codeplex.
The first task is to create a project using the template installed by WSPBuilder installer. The project must be a project to create a blank feature. Once the project was created we are going to add a new item. This item must be based in the template BlankFeature, one of the templates installed by WSPBuilder. The project in Visual Studio 2008 should be as we can see in Image 1.
Ok, the next step will be to create a class (FeatureEvents) in the root of the project as we can see in Image 1 and it must be inherit of SPFeatureReceiver, class of Sharepoint that. This class has 4 events that we need develop. In Section 2 we can see the name of events and a brief description.
1) FeatureActivated: This event will be fired when the feature was activated.
2) FeatureDeactivating: This event will be fired when the feature is Deactivating
3) FeatureInstalled: This event will be fired when the feature was installed
4) FeatureUnistalling: This event will be fired when the feature was uninstalling
The last step in modified the XML feature.xml to declare the feature, our assembly and our class where the events are developed. In Section 2 we can see the code for the feature.xml.
<Feature Id="e3954709-8993-417e-b8e8-9a5b3bca44aa"Title="FeatureEventsFired"Description="FeatureEventsFired"Version="220.127.116.11"Hidden="FALSE"Scope="Web"DefaultResourceFile="core"ReceiverAssembly="Siderys.Blog.Feature.FeatureEvents,Version=18.104.22.168, Culture=neutral, PublicKeyToken=711eed342842acee"ReceiverClass="Siderys.Blog.Feature.FeatureEvents.FeatureEventsClass"xmlns="http://schemas.microsoft.com/sharepoint/"><ElementManifests><ElementManifest Location="elements.xml"/></ElementManifests></Feature>
Once installed our package, the events will be fired and we catch it in our class.