Home > MOSS 2007 > SPFeatureDependencyCollection


August 7th, 2007 Leave a comment Go to comments

You can programmatically find all activated features that are dependent on a specific feature by using the following example. In this example, feature is stopped from being deactivated because dependant features are still in active mode.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Collections;
using System.Diagnostics;

namespace Configuration
public class Configurator : SPFeatureReceiver
public override void FeatureInstalled(SPFeatureReceiverProperties properties) {}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}
public override void FeatureActivated(SPFeatureReceiverProperties properties) {}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        SPSite site = properties.Feature.Parent as SPSite;
        SPFeatureCollection spfeatCol = site.Features;
        //iterate through all the features of the current site collection
       foreach (SPFeature feature in spfeatCol)

          // Get the collection of all features that are dependent on this feature
         SPFeatureDependencyCollection depCollection = feature.Definition.ActivationDependencies;
         foreach (SPFeatureDependency featureDependency in depCollection)
                if (featureDependency.FeatureId.Equals(properties.Feature.DefinitionId) && feature.Definition.Status.Equals(SPObjectStatus.Online))
                         throw new Exception(“Deactivation aborted! There is at least one dependant feature in active mode.”);

// Do the rest of the work here.


Categories: MOSS 2007 Tags:
  1. No comments yet.
You must be logged in to post a comment.