For a recent project I did, I had to activate a feature programatically.
I needed some research to achieve this, so I thought I'd just put it in a post. It's only a few lines of code, so nothing hard to do here ...
Basically, what it does is update the FeatureCollection object of a given Site or Site Collection. Adding a feature to this collection automatically activates it.
! Do make sure the feature is already installed in the farm/site/web/... when trying to activate it.
SPWeb web = new SPSite("http://yourserver.com").OpenWeb();
SPFeatureCollection featureCollect = web.Features;
featureCollect.Add(new Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), true); //True to force activation
That's all it takes :)
Hope it helps someone ...