listfeatures events

Dec 11, 2009 at 9:24 AM
Edited Dec 11, 2009 at 9:29 AM

Dear List Feature users,

I received a message from user alason with following message:

is there a way to use activate deactivate events for listfeatures instances like in standard fetaures ?

The answer is yes. List Features support events. I didn't document it yet, sorry for that. But here is some documentation:

A ListFeature has several events that can be adressed upon deployment:
  • FeatureAdding
  • FeatureAdded
  • FeatureActivating
  • FeatureActivated
  • FeatureDeactivating
  • FeatureDeactivated
  • FeatureRemoving
  • FeatureRemoved
As you can see, it extends the original SPFeature events by 2 synchronous (FeatureAdding, FeatureRemoving) and 2 asynchronous events (FeatureAdded, FeatureRemoved).
The way you implement a list feature event receiver is as follows:

<Property Key="ListFeature.EventReceivers.<new_guid>" Value="<namespace.classThatImplementsEventReceiver>, <assembly>, Version=<versionNumber>, Culture=neutral, PublicKeyToken=<signedAssemblyKey>"

Next you create a class that inherits from ListFeatureEventReceiver class. Here you can then override the eventhandler of your choice. This class should reside in a strong named assembly.
Remark: The property Key is in the format ListFeature.EventReceivers.<guid>. A guid should be added but anything that makes it unique can be used.
Dec 11, 2009 at 9:57 AM

Thank you very much. This was the only thing that i was missing.


Dec 11, 2009 at 10:19 AM

It works great. One more thing though. In the receiver class i would like to access a property defined in the feature. How to do it ?

Dec 11, 2009 at 10:37 AM

Got it, correct me if i am wrong:

ListFeatureSetting setting = properties.Feature.Settings.Get("propertyName");
string value = setting.Value;

Dec 11, 2009 at 11:05 AM

Awesome alason! ;-) You got it!

As ListFeatures can automatically fill in settings, you can also do the following:

public MyEventHandler : ListFeatureEventReceiver
   private string _propertyName
   public string propertyName
      get {return _propertyName;}
      set {_propertyName = value;}
   public override void FeatureAdded(...)
      // Do something with _propertyName, it is now automatically filled in!
      int i = propertyName.Length;

Good Luck!

Dec 15, 2009 at 10:28 AM


Another question popped up though. On the configuration screen the properties are entered into regular textboxes.

Is it possible use i.e. DropDownLists or other controls ?

Dec 17, 2009 at 10:22 PM

In theory, it's possible. But I haven't tried it yet. You can create your own list feature settings page and place your dropdowns on it. This page will open when users are opening the list feature's settings.

  • Create your aspx page, inheriting from SettingsPage
    You can use all kind of build in methods to let the page render the default buttons, header, settings, etc.
  • Add following property in your feature declaration:
    <property name="ListFeature.SettingsUrl">_layouts/MyCustomSettings.aspx</property>

This is what I have at the moment. (Maybe I'll create a more elaborate example when I have time) On my wishlist for list feature framwork, however, I have the plan to add type support for settings. This will allow the framework to render dropdownlists if necessary. But still far away. :-)

Good Luck!