R – Custom SharePoint feature in multiple scopes in document library – shows up as duplicates

sharepointsharepoint-2007

I have a custom feature which is an Edit Control Block (ECB) action in a document library that gets deployed as a solution package (WSP). When you pull down the dropdown next to a file, you see the feature and when the ECB action is selected, the user is redirected to a custom application page.

I allow this feature to be installed into all 4 different scopes: Farm, WebApplication, Site and Web. Each of them will be in a different solution package but share the same FeatureId, SolutionId etc. It is assumed that feature is only installed into one scope at a time. If an administrator deploys it, activates it and if we he/she wants to change the scope, deactivates it, everything works properly. If for some reason the administrator does not deactivate it first, the ECB action will have duplicate entries in the document library.

For example, say we install it as Site scope (site collection) and later decides we want it in Farm scope instead and don't deactivate it first and instead just go to the Solution Management and retract and remove it. If we look at the site collection where it was previously available, we don't see the ECB action.

If we then add the Farm scope solution package and deploy it, we will now see the ECB action in the site collection even though we have not deployed it and the feature.xml ActivateOnDefault attribute is set to false. If we then go ahead and activate it, we will now see two ECB actions.

Does anyone have any ideas? I have added the feature.xml and elements.xml below.

TIA,
Magnus

<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?>

RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="300"
ImageUrl="/_layouts/images/MyFeature/MyOtherPic.gif"
Title="My Feature"
Description="My ECB feature"
>

Best Answer

AFAIK, this behaviour is by design. You will need to add or extend a FeatureReceiver and override some of the methods, especially FeatureUninstalling where you need to deactivate your feature on every place where it is still activated.

You could log each activation e.g. using (top level) web properties.

Walkthrough: Creating a SharePoint Feature Receiver and Custom Link with WSS Extensions

Good Luck!