Tuesday, December 05, 2006

Installing Custom Group and Actions in WSS/MOSS Features

Another customization in WSS/MOSS! You can install your own custom feature other than out-of-box features that offered WSS/MOSS. You can add new actions or menus in any location in WSS/MOSS like Site Settings, Site Actions, Item Context Menu, and etc in Standard Menu.

By default, there have 5 groups - Look and Feel, Users and Permissions, Gallaries, Site Administration, Site Collection Administration.

To install new custom feature, create a new folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES. I name the folder as MyCustomGroupAndAction. Then we need to create an XML called feature.xml and another xml file that contains the feature definition. (featuredef.xml)

Feature.xml has several elements - <Feature>, <ActivationDependencies>, <ElementManifests> and <Properties> but the important ones are :

1. <Feature> (the root element) - Defines feature ID, scope (site, collection, etc), description and title.

2. <ElementManifests> - defines the feature definition, which links to the xml file that contains the definition.

In feature.xml

<?xml version="1.0" encoding="us-ascii"?>
<Feature Id="F863C1CF-897D-49c6-8600-7E6F3FC9D653"
Title="My New Feature"
Description="This is my new feature"
<ElementManifest Location="featuredef.xml" />

The ID of the feature is unique GUID. You need to generate new GUID for each new feature being created. To generate the GUID, you can go to Visual Studio -> Tools Menu -> Create GUID or launch the tool at C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\guidgen.exe.

The location attribute of <ElementManifests> specifies the location of feature definiton XML file.

In featuredef.xml

<?xml version="1.0" encoding="us-ascii"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
Title="My Custom Group" />

<CustomAction Id="MyCustomFeature"
Title="New Custom Feature"
<UrlAction Url="_layouts/layoutdesign.aspx"/>

The <CustomActionGroup> specifies the definition of new group to be created. Location attribute specifies where the custom group will reside. In this example, "Microsoft.SharePoint.SiteSettings" indicates that the new group will be in the Site Settings menu of WSS sites. Check Location and Group ID in MSDN for more information. Text in the Title attribute is the name of the group.

<CustomAction> is where the custom feature definition set. The location attribute MUST BE same as the location being specified in the group that the custom feature points to (in GroupID attribute). <UrlAction> element merely specifies URL of the custom application page.

It is about to install the feature ! Go to the command prompt, type

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o installfeature -name MyCustomGroupAndActions

The feature has just been installed. However, you need to activate the feature before using it. To activate it, you can type

stsadm -o activatefeature -filename MyFeature/feature.xml -url <server url>


go to http://<server name>/_layouts/manageFeatures.aspx, and you will see this

Click "Activate" button to activate the feature. Go to "Site Settings" and you will see this

You have completed installation of new custom group and feature !!


- Abigail - said...

Cool blog you have here. :)

mark6543 said...


I have created a Feature which is a timed job, every couple of minutes it connects to a web service to pull data into some lists within a site collection. The question I have is that when I move this timed job to another environment (say from development to test) it connects to a different web service so I want to have a config file so I can modify the connection to the web service without having to build the project again in visual studio which is my current deployment method. I do see in my build output folder it does create a config file but my deployment method is to take .dll file that is created and drop that into the GAC and then activate the feature using the stsadm tool.
Do you have any tips on how to connect a config file to a feature?

Garth said...

I had a similar issue and resolved it by adding the config settings to the MOSS web.config file. I then used the IConfigurationSectionHandler class to extract the info. It's very handy cause we put all configurations in our own custom xml format and then change it for production. (http://msdn2.microsoft.com/en-us/library/ms228056.aspx)