SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

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.

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:

 

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).


Posted 10-12-2007 1:00 AM by Waldek Mastykarz

Comments

SharePoint 2007 Link love: 10-14-2007 at Virtual Generations wrote SharePoint 2007 Link love: 10-14-2007 at Virtual Generations
on 10-14-2007 2:40 PM

Pingback from  SharePoint 2007 Link love: 10-14-2007 at  Virtual Generations

C.K. wrote re: Displaying Features' version in the Site (Collection) Features Overview
on 11-14-2007 4:51 AM

Ok, (hopefully) stupid question: if you install third-party webparts, will yr solution still work?

Mike Glaser wrote re: Displaying Features' version in the Site (Collection) Features Overview
on 11-14-2007 1:58 PM

Waldek,

Excellent solution. I like it al lot  and will try to implement it in our own sharepoint site. Besides this I will also mention it in my courses. This is probebly the only proper way to test version of your features.

Waldek Mastykarz wrote re: Displaying Features' version in the Site (Collection) Features Overview
on 11-14-2007 10:59 PM

C.K.: As long as you provide the version number in your Feature.xml, it will be displayed on the manage features page

Mike: Thank you and yes, you're right: at this point of time there is no other way in SharePoint to find out which Feature version has been installed

Ali B wrote re: Displaying Features' version in the Site (Collection) Features Overview
on 01-10-2008 2:11 AM

Excellent Work!

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.