Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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)
    {
        try
        {
            SPFeature feature = features[featureId];
            if (feature != null) return true;
        }
        catch { }
        return false;
    }
share|improve this answer
1  
+1 for clean approach! –  Falak Mahmood Sep 22 '11 at 7:08
add comment

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.

share|improve this answer
    
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 '11 at 0:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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