public static void RemoveAllAdminModifications(SPAdministrationWebApplication adminWebApp, List <string> names) { var modifications = new List <SPWebConfigModification>(); foreach (SPWebConfigModification modification in adminWebApp.WebConfigModifications) { if (modification.Owner == ModificationOwner) { modifications.Add(modification); } } foreach (SPWebConfigModification modification in modifications) { foreach (string name in names) { if (modification.Name == name) { adminWebApp.WebConfigModifications.Remove(modification); } } } adminWebApp.Update(); }
private static void ModifyAdminWebConfig(SPAdministrationWebApplication adminWebApp, string modificationName, string modificationPath, string modificationValue, SPWebConfigModification.SPWebConfigModificationType modificationType) { SPWebConfigModification modification = new SPWebConfigModification(modificationName, modificationPath); modification.Value = modificationValue; modification.Sequence = 0; modification.Type = modificationType; modification.Owner = ModificationOwner; try { adminWebApp.WebConfigModifications.Add(modification); adminWebApp.Update(); } catch (Exception ex) { EventLog eventLog = new EventLog(); eventLog.Source = ModificationOwner; eventLog.WriteEntry(ex.Message); throw ex; } }