P
Peb
Hello helpers,
I wish to a property setting to the application config file, So I did the
following:
System.Reflection.Assembly ass =
System.Reflection.Assembly.GetExecutingAssembly();
string fullProcessPath = ass.Location;
System.Reflection.AssemblyName assemblyName = ass.GetName();
string desiredDir = Path.GetDirectoryName(fullProcessPath);
string configPath = desiredDir + "\\" + assemblyName.Name + ".exe";
System.Configuration.SettingsProperty property = new SettingsProperty();
System.Configuration.SettingsProperty property = new
System.Configuration.SettingsProperty("LastDbFile");
property.DefaultValue = (object)"27122009.db";
property.IsReadOnly = false;
property.PropertyType = typeof(string);
property.Provider =
Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute),
new System.Configuration.UserScopedSettingAttribute());
if( Properties.Settings.Default.Properties["LastDbFile"] == null )
{
SettingsPropertyValue newPropValue = new
SettingsPropertyValue(property);
newPropValue.PropertyValue = "27122009.db";
Properties.Settings.Default.Properties.Add(property);
Properties.Settings.Default.PropertyValues.Add(newPropValue);
}
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
But the config file on disk does no change and so new property does not show
in this config file.
What am I doing wrong?
I wish to a property setting to the application config file, So I did the
following:
System.Reflection.Assembly ass =
System.Reflection.Assembly.GetExecutingAssembly();
string fullProcessPath = ass.Location;
System.Reflection.AssemblyName assemblyName = ass.GetName();
string desiredDir = Path.GetDirectoryName(fullProcessPath);
string configPath = desiredDir + "\\" + assemblyName.Name + ".exe";
System.Configuration.SettingsProperty property = new SettingsProperty();
System.Configuration.SettingsProperty property = new
System.Configuration.SettingsProperty("LastDbFile");
property.DefaultValue = (object)"27122009.db";
property.IsReadOnly = false;
property.PropertyType = typeof(string);
property.Provider =
Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute),
new System.Configuration.UserScopedSettingAttribute());
if( Properties.Settings.Default.Properties["LastDbFile"] == null )
{
SettingsPropertyValue newPropValue = new
SettingsPropertyValue(property);
newPropValue.PropertyValue = "27122009.db";
Properties.Settings.Default.Properties.Add(property);
Properties.Settings.Default.PropertyValues.Add(newPropValue);
}
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
But the config file on disk does no change and so new property does not show
in this config file.
What am I doing wrong?