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

Is there a way to determine if the Metadata Navigation and Filtering feature is activated on a site collection?

I've looped through the farm features, site features and web features but I can only find this feature at the farm level. However, this can be activated down at the site collection level.

SPFeatureCollection spfc = web.Features;
foreach (SPFeature f in spfc)
    {
        spew(f.Definition.DisplayName);
    }

SPFeatureDefinitionCollection spfdc = site.FeatureDefinitions; //this is empty
foreach (SPFeatureDefinition f in spfdc)
    {
        spew(f.DisplayName);
    }

I also saw TaxonomyFieldAdded but that doesn't seem to indicate that metadata is currently activated on the site collection.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

If you open the page http://your/sites/coll/web/_layouts/ManageFeatures.aspx and if you look at the html structure with your favorite tools (IE dev tools can do the job), you will see that the button "Enable" of the feature has this html :

<DIV 
    id=7201d6a4-a5d3-49a1-8c19-19c4bac6e668 
    class=ms-vb2>

<INPUT    id=ctl00_PlaceHolderMain_featact_rptrFeatureList_ctl21_ctl00_btnActivate 
        class=ms-ButtonHeightWidth 
        title="Activer la fonctionnalité" 
        onclick="javascript:__doPostBack('ctl00$PlaceHolderMain$featact$rptrFeatureList$ctl21$ctl00$btnActivate','')" 
        name=ctl00$PlaceHolderMain$featact$rptrFeatureList$ctl21$ctl00$btnActivate 
        value=Activer 
        type=button> 
</DIV>

The id of the DIV is the id of the feature you are looking for. This is useful because some features are hard to find by their internal name.

So in code, you should determine if its activated using :

public bool IsFeatureActivate(Guid featureID, SPWeb web)
{
    return web.Features.Cast<SPFeature>().Any(f=>f.Id == featureID);
}

public void Test()
{
    var web = GetMySPWeb();
    if(IsFeatureActivated(web, new Guid("7201d6a4-a5d3-49a1-8c19-19c4bac6e668"));
    {

    }
}
share|improve this answer
    
thanks. Works great. Nice note about the div id. –  Eonasdan Jul 19 '12 at 14:04
add comment

This is actually a web scoped activated feature. You can find this using powershell

Get-SPSite http://yoursitename | Get-SPWeb -Limit ALL | %{ Get-SPFeature -Web $_ } | Sort DisplayName -Unique | FT DisplayName,Id

You will find the feature listed as

MetaDataNav

Just iterate the same logic through your c# code and you should comfortably get the results.

share|improve this answer
    
thanks for the powershell version. –  Eonasdan Jul 19 '12 at 14:04
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.