Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interesaznt

15 views
Skip to first unread message

Peb

unread,
Dec 30, 2009, 10:22:55 AM12/30/09
to
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?


--
Thanks
Sharon


Peter Duniho

unread,
Dec 30, 2009, 12:39:26 PM12/30/09
to
Peb wrote:
> [...]

> 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

0 new messages