Using SPWebConfigModification, Part 6 - Putting it to work
So, using this code, you could embed in your Feature receiver a web.config file that looks like the aforementioned fragment. Read in the XML to an XmlDocument object, and then pass that XmlDocument along with your SPWebApplication or SPWebService’s WebConfigModification collection to a recursive starter method, like this:
private void AddModifications(XmlDocument doc, Collection<SPWebConfigModification> collection)
{
XmlNode docRoot = doc.DocumentElement.FirstChild.ParentNode;
SPWebConfigModification mod = new SPWebConfigModification(docRoot.Name, doc.DocumentElement.Name);
mod.Sequence = _seq = 0;
mod.Owner = _modificationOwner;
AddChildren(collection, docRoot, mod);
}
Finally, be sure to apply those changes to the content service, and update the SPWebApplication or the SPWebService into which you’ve put those modifications:
SPWebService.ContentService.ApplyWebConfigModifications();
currentWebApp.Update();
I hope this helps everyone in their SharePoint tasks!