Installing WebApplication scoped feature through code - SharePoint
-
28-10-2019 - |
Question
I've a WebApplication scoped feature which I need to install through code.
In short, I need to perform
stsadm -o installfeature -name MyFeature
through code. Any ideas?
Solution
Try this code:
public void InstallFeature(string name, bool force)
{
string relativePath = name + @"\feature.xml";
Microsoft.SharePoint.Administration.SPFarm.Local.FeatureDefinitions.Add(relativePath, Guid.Empty, force);
}
OTHER TIPS
Have a look at the code for the SharePoint Solution Installer on Codeplex.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow