How to add and read properties from the feature.xml

1 minute read

I knew it is was possible to provide features with properties but I never found a useful situation till a few days ago.

So know is the question how do you add properties to your feature.xml? You can accomplish this by adding a properties tag to the feature.

 <?xml version="1.0" encoding="utf-8" ?>
 <Feature Id="FeatureID"
              Description="Example for working with feature properties"
     ReceiverAssembly="Assembly, Version=, Culture=neutral, PublicKeyToken=Token"
              ReceiverClass="The Receiver class"
 <ElementManifests />
         <Property Key ="Variation" Value="Dutch" />
         <Property Key ="VariationLabel" Value="nl-NL" />

In this example I saved the variation label I want to add to the variation.

If you would Activate the feature you can read out the Property Variation and Variation Label like this:

/// <summary>
 /// Feature Activation
 /// </summary>
 ///<param name="properties">Feature properties</param>
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    //Get property collection
    SPFeaturePropertyCollection featureProperties = properties.Feature.Properties;

    //Get seperate properties with the key
    string variationDisplayName = feautureProperties[Variation].toString();
    string variationLabel= feautureProperties[VariationLabel].toString();