I have three site collection features used to set branding throughout the site collection. I want to prevent the accidental activation of one of the features if one of the three is already activated; otherwise they'll override each other.

I'm assuming that logic in the FeatureActivated portion of the feature's event receiver is the right place to put the logic in, but I'm unsure how to do that logic and return a message to the user saying that the activation was prevented because there's already a feature activated.

Any thoughts?

2 Answers 2


Yep the place to do it is the feature activated portion of the feature receiver. You can check if one of your others are already activated and throw an exception if they are.

Certain exceptions when thrown will display the message to the end user, others will just say an unexpected event occurred. I think if you throw an applicationexception it will display the message.

This is some code i've used before to test feature activation:

    public static bool IsFeatureActive(Guid featureId, SPFeatureCollection features)
            SPFeature feature = features[featureId];
            if (feature != null) return true;
        catch { }
        return false;
  • 1
    +1 for clean approach! Sep 22, 2011 at 7:08

The big problem with the FeatureActivated is that the feature has been activated! It is now too late... Your files have already been deployed.

I would suggest to hide the feature to prevent the user to activate it. This way, "only" administrators with PowerShell access could activate those features in your environment.

  • It's just a small subset of folks that'd have the ability to activate it anyway, I just wanted an extra control. It's not worth going through the hassle of making it hidden just for that. Thanks though.
    – webdes03
    Sep 22, 2011 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.