maandag, augustus 13, 2007

Adding AppSettings to a Sharepoint Web Application Web.Config

I use this code to add key/values to the web.config during installation of features


(using Microsoft.SharePoint.Administration;)

string siteName = "http://moss";
SPSite site = .....;
SPWebApplication webApp = site.WebApplication;
System.Collections.ObjectModel.Collection allModifications= webApp.WebConfigModifications;

AddNewAppSetting(allModifications,"testkey1","testvalue1");
AddNewAppSetting(allModifications,"testkey2","testvalue2");

SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();

------

private void AddNewAppSetting(System.Collections.ObjectModel.Collection allModifications,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:

1 opmerking:

indiroma zei

Hi! Your blog is simply super. you have create a differentiate. Thanks for the sharing this website. it is very useful professional knowledge. Great idea you know about company background.
Customized application development