Tuesday, 23 September 2014

SharePoint remove web.config entries when a feature is de-activated in WSS

protected void removeWebConfigEntries(SPWebApplication oWebApp, string owner)
{
Collection<SPWebConfigModification> oCollection = oWebApp.WebConfigModifications;
int iStartCount = oCollection.Count;
for (int c = iStartCount - 1; c >= 0; c--)
{
SPWebConfigModification oModification = oCollection[c];
if (oModification.Owner == owner)
oCollection.Remove(oModification);
}
if (iStartCount > oCollection.Count)
{
oWebApp.Update();
SPFarm.Local.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
}
view raw gistfile1.cs hosted with ❤ by GitHub