title: Sharepoint 2007 - cant find my modifications to web.config in SpWebApplication.WebConfigModifications
body: <p>I cant seem to find the modifications I made to web.config in my FeatureRecievers Activated event. I try to get the modifications from the SpWebApplication.WebConfigModifications collection in the deactivate event, but this is always empty.... And the strangest thing is that my changes are still reverted after deactivating the feature...</p>
  
  <p>My question is, should I not be able to view all changes made to the web.config files when accessing the SpWebApplication.WebConfigModifications collection in the Deactivating event? How should I go about to remove my changes explicitly?</p>
  
  <p><pre><code>
   public class FeatureReciever : SPFeatureReceiver
  {
      private const string FEATURE_NAME = "HelloWorld";
      private class Modification
      {
          public string Name;
          public string XPath; 
          public string Value; 
          public SPWebConfigModification.SPWebConfigModificationType ModificationType;
          public bool createOnly;</p>
  
      public Modification(string name, string xPath, string value, SPWebConfigModification.SPWebConfigModificationType modificationType, bool createOnly)
      {
          Name = name;
          XPath = xPath;
          Value = value;
          ModificationType = modificationType;
          this.createOnly = createOnly;
      }
  }
  
  private Modification[] modifications =
  { 
      new Modification("connectionStrings", "configuration", "&lt;connectionStrings/&gt;", SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, true),
      new Modification("add[@name='ConnectionString'][@connectionString='Data Source=serverName;Initial Catalog=DBName;User Id=UserId;Password=Pass']", "configuration/connectionStrings", "&lt;add name='ConnectionString' connectionString='Data Source=serverName;Initial Catalog=DBName;User Id=UserId;Password=Pass'/&gt;", SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, false)
  };
  
  public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {
      SPSite siteCollection = (properties.Feature.Parent as SPWeb).Site as SPSite;
      SPWebApplication webApplication =  siteCollection.WebApplication;
      siteCollection.RootWeb.Title = "Set from activating code at " + DateTime.Now.ToString();
  
      foreach (Modification entry in modifications)
      {
          SPWebConfigModification webConfigModification = CreateModification(entry);
          webApplication.WebConfigModifications.Add(webConfigModification);
      }
      webApplication.Farm.Services.GetValue&lt;SPWebService&gt;().ApplyWebConfigModifications();
      webApplication.WebService.Update();
  }
  
  public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
  {
      SPSite siteCollection = (properties.Feature.Parent as SPWeb).Site as SPSite;
      SPWebApplication webApplication = siteCollection.WebApplication;
      siteCollection.RootWeb.Title = "Set from deactivating code at " + DateTime.Now.ToString();
  
      IList&lt;SPWebConfigModification&gt; modifications = webApplication.WebConfigModifications;
      foreach (SPWebConfigModification modification in modifications)
      {
          if (modification.Owner == FEATURE_NAME)
          {
              webApplication.WebConfigModifications.Remove(modification);
          }
      }
  
      webApplication.Farm.Services.GetValue&lt;SPWebService&gt;().ApplyWebConfigModifications();
      webApplication.WebService.Update();
  }
  
  public override void FeatureInstalled(SPFeatureReceiverProperties properties)
  {
  }
  
  public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
  {
  }
  
  private SPWebConfigModification CreateModification(Modification entry)
  {
      SPWebConfigModification spWebConfigModification = new SPWebConfigModification()
      {
          Name = entry.Name,
          Path = entry.XPath,
          Owner = FEATURE_NAME,
          Sequence = 0,
          Type = entry.ModificationType,
          Value = entry.Value
      };
  
      return spWebConfigModification;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks for your time.
  /Hans</p>