以编程方式删除Web.config设置

时间:2011-11-17 16:28:20

标签: sharepoint sharepoint-2010 web-config

无法以编程方式删除Web.config设置时,我尝试this msdn code(同时使用SPWebService和SPWebApplication)希望它可以正常工作但是虽然添加有效,但删除似乎不起作用。

我正在使用Add on a feature Activated方法并删除已停用的功能,该功能具有WebApplication Scope。

我已经尝试了上面提到的脚本,但结果保持不变。

是否有一些我不知道的必要设置?

1 个答案:

答案 0 :(得分:1)

对于任何可能感兴趣的人,我得到了这样的工作:

而不是像msdn代码那样在for循环之外进行删除和更新,而不是在内部执行:

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();
}