How do I add a feature with a feature receiver event handler

To add a feature with a feature receiver event handler your feature.xml file needs to have ReceiverAssembly and ReceiverClass added to the Feature element:

<Feature  Id=”[GUID]”
          Title=”FeatureWithReceiver”
          Description=”Description for FeatureWithReceiver”
          Version=”12.0.0.0″
          Hidden=”FALSE”
          Scope=”Web”
          ReceiverAssembly=”[STRONG NAME]”
          ReceiverClass=”MyNameSpace.FeatureWithReceiver”
          xmlns=”http://schemas.microsoft.com/sharepoint/”>

The strong name is the four-part name you get when you sign the assembly, and the receiver class is the namespace and the class you want to handle the event.

Next, make sure your assembly includes a class that inherits from the SPFeatureReceiver class:

namespace MyNameSpace
{
    class FeatureWithReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // Do stuff when feature is activated
        }

[...]

}

No related posts.

Posted under Developer

This post was written by furuknap on December 8, 2008

Tags:

Do you want to contribute to this answer?

Name (required)

Email (required)

Website

Comments

More Blog Post

Previous Post: