public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPWebApplication webApp;
                WebConfigModifications webConfigMods;

                webApp = (SPWebApplication)properties.Feature.Parent;
                webConfigMods = new WebConfigModifications();

                //load the web.config settings from the feature root
                //xmlDoc = new XmlDataDocument();
                //xmlDoc.Load(string.Format("{0}\\{1}", properties.Feature.Definition.RootDirectory, "web.config"));

                //configuration/SharePoint/SafeControls
                //xPath = "configuration/SharePoint/SafeControls";
                //AddWebConfigNodes(xPath, ref xmlDoc, ref webConfigMods, ref webApp);

                //configuration/appSettings
               // xPath = "configuration/appSettings";
                //AddWebConfigNodes(xPath, ref xmlDoc, ref webConfigMods, ref webApp);

                //configuration/appSettings
                //xPath = "configuration/configSections";
                //AddWebConfigNodes(xPath, ref xmlDoc, ref webConfigMods, ref webApp);

                //configuration
                //xPath = "configuration/system.serviceModel";
                //AddWebConfigNodes(xPath, ref xmlDoc, ref webConfigMods, ref webApp);

                webApp.Farm.Servers.GetValue<SPWebService>().ApplyWebConfigModifications();
                webApp.Update();

            }
            catch (Exception ex)
            {
                WriteToEventLog(EventType.Error, ex.Message);
            }
        }
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
 {
     SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;
      WebConfigModifications webConfigMods = new WebConfigModifications();
      webConfigMods.RemoveWebConfigNodes(webApp);
      webApp.Farm.Servers.GetValue<SPWebService>().ApplyWebConfigModifications();
      webApp.Update();
 }
 private void AddWebConfigNodes(string xPath, ref XmlDataDocument xmlDoc, ref WebConfigModifications webConfigMods, ref SPWebApplication webApp)
 {
     foreach (XmlNode node in xmlDoc.SelectSingleNode(xPath))
     {
         if (node.NodeType != XmlNodeType.Comment)
         {
             webConfigMods.AddWebConfigNode(webApp, xPath, node, node.Attributes);
         }
     }
 }