How to activate or deactivate feature using sharepoint object model

To activate feature through Sharepoint object model use the following code

Activate a feature:

spSite.Features.Add(“featureId”)

Deactivate a feature:

spSite.Features.Remove(“featureId”)

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

I have been working on packaging a Site Definition using the Solutions Builder for VS 2008. I have been able to create the solution and deploy it, but none of the features are activated. So I found the SiteProvisioning.cs which allows the creation of code executed during site provisioning to activate features. I have tried an number of different code snippets using SPweb.Feature.Add and SPsite.Feature.add can not get it to work correctly. I can not find a fully functional example of this very simple step anywhere. Does anyone have functioning example of activating any feature in the SiteProvisioning.cs file?

Leave a comment

(required)

(required)