sharepointsharepoint-2010sharepoint-feature

feature versioning in sharepoint



I've followed following link to implement feature versioning: http://sisharepoint.wordpress.com/2010/01/21/using-the-featureupgrading-event-to-upgrade-features-sharepoint-2010/

I am new to sharepoint and the requirement is to show the versions of features in my site. Is it possible?
I am not able to see the version anywhere in the site. I can see appropriate version in the feature.xml file in feature folder of 14 hive. Just want to know that is it possible to see the versions of each deploy in sharepoint site also?If yes then where can I see it?

Thanks,
Priya


Solution

  • If custom solution fits your requirement then you can try following ways to find activated feature versions.

    1. Use SPFarm.FeatureDefinitions

    to get all activated features in the Farm -

    SPFeatureDefinitionCollection farmFeatures = SPFarm.Local.FeatureDefinitions;
    foreach (SPFeatureDefinition feature in farmFeatures)
    {
    ....
    }
    
    1. To find a version of a particular feature

      var spFarm = SPFarm.Local;
      System.Version version = spFarm.FeatureDefinitions["YourFeatureName"].Version;
      
    2. Use SPContext.Current.SiteFeatures or SPContext.Current.Site.Features

      var siteFeatures= SPContext.Current.SiteFeatures;
      foreach (SPFeature sf in siteFeatures)
      

      {

      variable = sf.Definition.DisplayName;

      variable = sf.Definition.Version.ToString();
      }
      

    4 Use SPContext.Current.WebFeatures or SPContext.Current.Web.Features

    var webFeatures= SPContext.Current.WebFeatures;
    
    foreach (SPFeature webFtr in webFeatures)
    {
    variable= webFtr.Definition.DisplayName;
    variable= webFtr.Definition.Version.ToString();
    }
    

    Hope this helps.