Upisivanje/menjanje app settings-a treba podeliti na one sa User i Application scope-om, ja sam koristio sledece metode,
mozda nekom budu od pomoci:
za User scope:
Code:
private static void SaveUserSettingDefault(string groupname,string clientSectionName, string settingName, object settingValue)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// find section group
ConfigurationSectionGroup group = config.SectionGroups[@groupname];
if (group == null) return;
// find client section
ClientSettingsSection clientSection = group.Sections[clientSectionName] as ClientSettingsSection;
if (clientSection == null) return;
// find setting element
SettingElement settingElement = null;
foreach (SettingElement s in clientSection.Settings)
{
if (s.Name == settingName)
{
settingElement = s;
break;
}
}
if (settingElement == null) return;
// remove the current value
clientSection.Settings.Remove(settingElement);
// change the value
settingElement.Value.ValueXml.InnerText = settingValue.ToString();
// add the setting
clientSection.Settings.Add(settingElement);
// save changes
config.Save(ConfigurationSaveMode.Full);
}
za Connection string, Application scope:
Code:
private static void SaveConnectionString(string connstringname,string conectionstring)
{
// Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Create a connection string element and
// save it to the configuration file.
// Create a connection string element.
ConnectionStringSettings csSettings =
new ConnectionStringSettings(connstringname, @conectionstring);
// Get the connection strings section.
ConnectionStringsSection csSection =
config.ConnectionStrings;
// Remove element.
csSection.ConnectionStrings.Remove(csSettings);
// Add the new element.
csSection.ConnectionStrings.Add(csSettings);
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
}