3

Having trouble on removing Web.config settings programmatically I tried this msdn code (using both SPWebService and SPWebApplication) hoping it would work but although the adding works, the remove doesn´t seem to work.

I'm using the Add on a feature Activated method and the remove on a feature deactivated and the feature has WebApplication Scope.

I've tried the mentioned script but the result stayed the same.

Is there some necessary setting that I'm not aware of?

Pedro Fonseca
  • 198
  • 1
  • 16

1 Answers1

1

For anyone who may be interested, I got it working like this:

Instead of doing the remove and update outside the for cycle like the msdn code I do it inside:

int modsCount1 = modsCollection.Count;
for (int i = modsCount1 - 1; i > -1; i--)
{
    if (modsCollection[i].Owner == "User Name")
    {
        configModFound = modsCollection[i];
    }
    // Remove it and save the change to the configuration database  
    modsCollection.Remove(configModFound);
    webApplication.Update();
}
Pedro Fonseca
  • 198
  • 1
  • 16