Domanda

I am using the following code to remove a web.config modification which added to web.config via one feature

        Collection<SPWebConfigModification> applicationModifications = webApplication.WebConfigModifications;
        SPWebConfigModification browserCapsConfig = null;

        int modsCount = applicationModifications.Count;
        for (int i = modsCount - 1; i > -1; i--)
        {
            if (applicationModifications[i].Owner == "OWNER_NAME")
            {
                browserCapsConfig = applicationModifications[i];
            }
        }

        if (browserCapsConfig != null)
        {
            applicationModifications.Remove(browserCapsConfig);
            webApplication.Update();
            webApplication.WebService.ApplyWebConfigModifications();
        }

All web.config modifications are retrieved in collection properly but the thing is while removing it, it is removed from the collection (unable to retrieve it anymore) but not from the web.config. The added modification still there. I tried the same code in SharePoint feature and a console application and getting the same behavior.

Anything missing I should do to remove it from the web.config file?

È stato utile?

Soluzione

There's nothing wrong with your code above, so this almost certainly has something to do with your SPWebConfigModification object's "Name" value.

The SPWebConfigModification.Name property (and the Name parameter in the SPWebConfigModification's constructor) are actually XPath expressions that uniquely identify the config entry. SharePoint uses this XPath expression to locate the modification when you try to remove or update it, hence if you haven't set it properly then it can't be removed.

See these resources for more info and correct naming conventions:

http://blogs.devhorizon.com/reza/2008/01/05/spwebconfigmodifications-top-6-issues/

http://social.msdn.microsoft.com/Forums/da-DK/sharepointdevelopment/thread/03f5b878-0f74-48ab-8049-ed4264a0b62a

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top