"Mufasa" <jb@nowhere.comwrote in message
news:uP**************@TK2MSFTNGP03.phx.gbl...
Can somebody please post code that will show how to write to the config
file?
I use the following, specifically for the appSettings section:
using System.Configuration;
/// <summary>
/// Adds / updates appSettings with the specified key/value pair dictionary
/// </summary>
/// <param name="pdicSettings">Dictionary of key/value pairs</param>
/// <returns>Boolean</returns>
public static bool SaveSettings(Dictionary<string, stringpdicSettings)
{
Configuration objConfigFile =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
bool blnKeyExists;
foreach (KeyValuePair<string, stringkvpSetting in pdicSettings)
{
blnKeyExists = false;
foreach (string strKey in
objConfigFile.AppSettings.Settings.AllKeys)
{
if (strKey == kvpSetting.Key) // key already exists
{
blnKeyExists = true;
objConfigFile.AppSettings.Settings[kvpSetting.Key].Value =
kvpSetting.Value;
break;
}
}
if (!blnKeyExists) // key doesn't already exist, so add it
{
objConfigFile.AppSettings.Settings.Add(kvpSetting. Key,
kvpSetting.Value);
}
}
objConfigFile.Save(ConfigurationSaveMode.Modified) ;
ConfigurationManager.RefreshSection("appSettings") ;
return true;
}
--
http://www.markrae.net