Sunday, April 12, 2009

Activating feature programatically

Scenario:
Someone asked me how to activate features programatically.

Solution:
I told you, I love Object Model. :-)

Code:

SPWeb web = (SPWeb) properties.Feature.Parent;
if (web.Features.Item(new Guid("FEATURE_GUID_VALUE_HERE"")) == null)
{
web.Features.Add(new Guid("FEATURE_GUID_VALUE_HERE"));
}
Note:
You can bundle multiple feature activation using this technique.

0 comments: