{"id":17,"date":"2007-08-07T18:58:00","date_gmt":"2007-08-07T23:58:00","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=17"},"modified":"2007-11-21T17:37:06","modified_gmt":"2007-11-21T22:37:06","slug":"spfeaturedependencycollection","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/07\/spfeaturedependencycollection\/","title":{"rendered":"SPFeatureDependencyCollection"},"content":{"rendered":"<p>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.<\/p>\n<p> using System;<br \/>\n using System.Collections.Generic;<br \/>\n using System.Text;<br \/>\n using Microsoft.SharePoint;<br \/>\n using Microsoft.SharePoint.Administration;<br \/>\n using System.Collections;<br \/>\n using System.Diagnostics;<\/p>\n<p> namespace Configuration<br \/>\n {<br \/>\n public class Configurator : SPFeatureReceiver<br \/>\n {<br \/>\n public override void FeatureInstalled(SPFeatureReceiverProperties properties) {}<br \/>\n public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}<br \/>\n public override void FeatureActivated(SPFeatureReceiverProperties properties) {}<br \/>\n public override void FeatureDeactivating(SPFeatureReceiverProperties properties)<br \/>\n {<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SPSite site = properties.Feature.Parent as SPSite;<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SPFeatureCollection spfeatCol = site.Features;<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/iterate through all the features of the current site collection<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach (SPFeature feature in spfeatCol)<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/p>\n<p> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Get the collection of all features that are dependent on this feature<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SPFeatureDependencyCollection depCollection = feature.Definition.ActivationDependencies;<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach (SPFeatureDependency featureDependency in depCollection)<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (featureDependency.FeatureId.Equals(properties.Feature.DefinitionId) &amp;&amp; feature.Definition.Status.Equals(SPObjectStatus.Online))<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 throw new Exception(&#8220;Deactivation aborted! There is at least one dependant feature in active mode.&#8221;);<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0}<br \/>\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p> \/\/ Do the rest of the work here.<\/p>\n<p> }<br \/>\n }<br \/>\n }<\/p>\n<p> <img loading=\"lazy\" decoding=\"async\" width=\"1\" src=\"\/\/blogs.devhorizon.com\/aggbug.aspx?PostID=491\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[3],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-moss-2007","tag-moss-2007"],"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}