Displaying Features' version in the Site (Collection) Features Overview

For each solution we develop for our customers we reuse a set of internal components we have developed – a kind of baseline library. As we use it we fix some errors and add some new functionality. To distinguish the different releases we modify the version of the assembly containing all the logic and the feature version as well. While working on several projects at the same with different project teams we found it quite difficult to check the assembly version each time you want to be sure you are using the latest version. That’s when I have decided to modify the page displaying Site and Site Collection feature and extend it with displaying the version of each feature stored within the feature.xml file.

DisplayingFeaturesVersionInTheSite1

First of all I have found out that one and the same page is being used for both Site and Site Collection Features. After a little research on the ManageFeatures.aspx page I have found that the task of displaying the list of features is contained within a separate control: FeatureActivator.ascx residing in 12\CONTROLTEMPLATES.

To obtain the version for each feature I have created the following method:

public static string GetFeatureVersionById  
  (string featureId, string scope)
{
  Guid id = new Guid(featureId);
  SPFeatureDefinition fd;

  if (!String.IsNullOrEmpty(scope) &&
    scope.ToLower() == "site")
  {
    foreach (SPFeature f in
      SPContext.Current.Site.Features)
    {
      fd = f.Definition;
      if (fd.Id.Equals(id))
        return fd.Version.ToString();
    }
  }
  else
  {
    foreach (SPFeature f in
      SPContext.Current.Web.Features)
    {
      fd = f.Definition;
      if (fd.Id.Equals(id))
        return fd.Version.ToString();
    }
  }

  return null;
}

To be able to use this method within the control I have added a reference to my assembly at the top of the control:

<%@ Assembly Name="Imtech.SharePoint.WSSGUI,  
Version=1.0.0.0, Culture=neutral, PublicKeyToken=token" %>  

Finally I have added a reference to my method at the end of the row displaying the Feature title:

<%# Imtech.SharePoint.WSSGUI.Common.GetFeatureVersionById(  
  DataBinder.Eval(Container.DataItem, "FeatureId", ""),
  Page.Request.QueryString["Scope"])%>

Because there are two item templates you need to add the line above in the AlternatingItemTemplate section as well.

As I have just modified modify an out-of-the-box SharePoint control I have decided to incorporate my changes in a copy of it instead replacing the existing one. It’s not such a good idea to modify SharePoint files: they might be replaced by SharePoint hotfixes, updates, service packs or any other features. Therefore it is recommended to use your own copies of the files you edit.

To make use of my copied and extended control I had to copy the ManageFeatures.aspx page as well and replace the reference to the control with the one I’ve just modified:

<%@ Register TagPrefix="wssuc" TagName="FeatureActivator"  
src="~/_controltemplates/ImtechFeatureActivator.ascx" %>  

Then I have spotted another challenge: I had to replace the links to the Site Features and Site Collection Features on the Site Settings page with a reference to the ImtechManageFeatures.aspx:

DisplayingFeaturesVersionInTheSite2

The menus on the Site Settings page are created, just like the Site Action menu using the CustomAction element in an Element Manifest. These menus are created using the SiteSettings feature. In the SiteSettings.xml you can find all of the items showed on the Site Settings page. These two actions are ManageSiteFeatures and ManageSiteCollectionFeatures. To replace the Urls of these links, I had to hide them and create my own copies with the correct link. You hide the items as follows:

<HideCustomAction HideActionId="ManageSiteFeatures"  
       Id="HideManageSiteFeatures"
       GroupId="SiteAdministration"
       Location="Microsoft.SharePoint.SiteSettings" />
<HideCustomAction HideActionId="ManageSiteCollectionFeatures"  
       Id="HideManageSiteCollectionFeatures"
       GroupId="SiteCollectionAdmin"
       Location="Microsoft.SharePoint.SiteSettings" />

And then add your copy:

<CustomAction  
  Id="ImtechManageSiteFeatures"
  GroupId="SiteAdministration"
  Location="Microsoft.SharePoint.SiteSettings"
  Rights="ManageWeb"
  Sequence="80"
  Title="$Resources:SiteSettings_ManageSiteFeatures_Title;">
  <UrlAction
   Url="_layouts/ImtechManageFeatures.aspx" />
</CustomAction>  
<CustomAction  
   Id="ImtechManageSiteCollectionFeatures"
   GroupId="SiteCollectionAdmin"
   Location="Microsoft.SharePoint.SiteSettings"
   RequireSiteAdministrator="TRUE"
   Sequence="45"
   Title="$Resources:SiteSettings_ManageSiteCollectionFeatures_Title;">
  <UrlAction
   Url="_layouts/ImtechManageFeatures.aspx?Scope=Site" />
</CustomAction>  

To make it all work you have to first modify the id’s (they have to be unique) and make the links point to the modified version of the ManageFeatures.aspx application page. To wrap it all up you could put it all in a Solution which deploys this Feature. Upon activating it the links will be altered and you will be able to use the extended functionality.

Having access to the features’ version works pretty well for me – especially in dynamic environments with new releases on regular basis. You could take this concept even further and extend it with your own properties that your development team uses. While using my customized Site (Collection) Features page I have discovered that there are a few more pages (like DeactivateFeature.aspx) which link the original ManagaFeatures.aspx. To make the user experience complete you could research these pages and make them reference your extended copy. Let me know if you would like to get this extension as a Solution (.wsp).

Comments

comments powered by Disqus