我有一個關於在功能衝壓web.config文件中修改一個小問題在這裏(SP2010 [Web應用程序級別功能,激活缺省])問題更改Web.config文件的SharePoint
我面臨兩個怪問題
- 像(添加子節點)應用的修改在web.config中出現多次。
- 在功能停用時,我將刪除對所有者的修改,它獲得修改,但是 這些不會被刪除。
我在功能激活過程中使用了下面的代碼片段。
ModificationEntry[] enries =
{
new ModificationEntry("someName", "someSection", SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode)
};
SPWebApplication WebApp = (SPWebApplication)properties.Feature.Parent;
WebApp.WebConfigModifications.Clear();
foreach (ModificationEntry entry in enries)
{
// CreateModification simply return me SPWebConfigModification
SPWebConfigModification configModificationItem = CreateModification(entry, properties.Feature.DefinitionId.ToString());
if (!WebApp.WebConfigModifications.Contains(configModificationItem))
{
WebApp.WebConfigModifications.Add(configModificationItem);
}
}
WebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
WebApp.Update();
這就是我正在做的功能停用。
if (webApp != null)
{
Collection<SPWebConfigModification> collection = webApp.WebConfigModifications;
int iStartCount = collection.Count;
// Remove any modifications that were originally created by the owner.
for (int c = iStartCount - 1; c >= 0; c--)
{
SPWebConfigModification configMod = collection[c];
if (configMod.Owner == properties.Feature.DefinitionId.ToString())
collection.Remove(configMod);
}
// Apply changes only if any items were removed.
if (iStartCount > collection.Count)
{
webApp.Update();
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
}
請評論!
其中是ModificationEntry/CreateModification的代碼。你似乎沒有一個'路徑'變量在任何地方(除非是someSection),但那麼'價值' – djeeg 2011-02-03 22:18:16