How do I flush out invalid SPWebConfigModifications?

I tried to execute some invalid modifications as part of a solution and now I cannt get rid of them, everytime I run ApplyWebConfigModifications it tries to execute the invalid modifications.

How do flush them out of the system?

有帮助吗?

解决方案

For future reference (after banging my head on the wall for 3 days):

You can use this tool:

http://ianankers.wordpress.com/2011/07/14/web-config-modification-manager-for-sharepoint-2010/

It will list all the mods for every WebApp installed in your farm, you can add new ones and remove old ones.

The tool will only list modifications at webapp level, if you installed mods at the farm level you need to run a script like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;

namespace ModTool
{
    class Program
    {
        static void Main(string[] args)
        {

            SPSite site = new SPSite(args[0]);
            SPWebService service = site.WebApplication.Farm.Services.GetValue<SPWebService>();


            if (args.Length == 1 || string.IsNullOrEmpty(args[1]))
            {
                Console.Out.WriteLine("Listing all Mods and Owners");
                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    Console.Out.WriteLine("Mod:" + mod.Name + ", Owner:" + mod.Owner);
                }
            }
            else
            {
                Console.Out.WriteLine("Removing all mods owner:" + args[1] + ", reference site:" + args[0]);

                List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>();

                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    if (mod.Owner == args[1])
                    {
                        toDelete.Add(mod);
                    }
                }

                Console.Out.WriteLine("Found " + toDelete.Count + "Mods");



                foreach (SPWebConfigModification mod in toDelete)
                {
                    service.WebConfigModifications.Remove(mod);
                }
                service.Update();
                SPWebService.ContentService.ApplyWebConfigModifications();
                Console.Out.WriteLine("Done!!");
            }
        }
    }
}

Usage:

ModTool http://site - List all the mods for the farm, site is just an entry point
ModTool http://site owner -Deletes all the mods for the far wich owner is "owner"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top