The SPWebConfigModification class allows developers to write code that will make modifications to the web.config files of SharePoint sites. This is quite often necessary when you want to deply SharePoint customizations together with configuration settings. Using the SPWebModification class is not without any danger! 🙂 You can mess up your web.config files especially if you don’t think about how you want to be able to undo your changes. Mark Wagner wrote an excellent article about the best practices related to the SPWebConfigModification class; required reading for every SharePoint developer. Mark explains some very important things you should know to get started:



  • To save the modifications, you must use of the following code:
    myWebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    myWebApp.Update();

  • Only call this code once in your feature handler, otherwise you get the error “A web configuration modification operation is already running.

Great info Mark, and please do create an complete example of the best practices, packaged in a feature!