Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Removing configuration Settings from Web config in SharePoint 2010

Removing configuration Settings from Web config in SharePoint 2010

The following example shows how to remove a configuration setting from sharepoint 2010 web config file. To know how to add a setting in web config file see the Post how to access SharePoint web config Programmatically

example :

SPWebConfigModification configModFound = null;
SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(“http://SPSite/”));
Collection modsCollection = webApplication.WebConfigModifications;

// Find the most recent modification of a specified owner
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();

// Reapply all the configuration modifications
webApplication.Farm.Services.GetValue().ApplyWebConfigModifications();

No comments:

Post a Comment