(using Microsoft.SharePoint.Administration;)
string siteName = "http://moss";
SPSite site = .....;
SPWebApplication webApp = site.WebApplication;
System.Collections.ObjectModel.CollectionallModifications= webApp.WebConfigModifications;
AddNewAppSetting(allModifications,"testkey1","testvalue1");
AddNewAppSetting(allModifications,"testkey2","testvalue2");
SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();
------
private void AddNewAppSetting(System.Collections.ObjectModel.CollectionallModifications,string name, string value)
{
SPWebConfigModification modification = new SPWebConfigModification(string.Format
("add[@key='{0}']", name), "/configuration/appSettings");
modification.Type =
SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = string.Format(CultureInfo.InvariantCulture,string.Format
("",name,value) );
if (allModifications.Contains(modification))
{
allModifications.Remove(modification);
}
allModifications.Add(modification);
}
Sources:
Geen opmerkingen:
Een reactie posten