Interesaznt

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?
 
P

Peter Duniho

Peb said:
[...]
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.

I don't really understand the code example. There's a bunch of code
that seems unrelated to the use of the Properties.Settings.Default
instance of the Settings class.

But as far as the Settings class goes, application-scoped properties are
read-only.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top