xxldoener
xxldoener

Reputation: 43

C# Settings File doesn't show changes

I was playing around with some settings in my C# console Application. I want to save a string to the settings.settings File, which worked by creating a setting in Designview (I called it teststring). I assigned the Value "Hello World!". When I access it during runtime with Properties.Settings.Default.teststring I get back the assigned value. So far so good. Now this is where things get odd: When I assign a new value like Properties.Settings.Default.teststring = "This is a new test" and save it by Properties.Settings.Default.Save();, the value gets saved as expected.

However: The Value in the Designview stays the same ("Hello World!") and when I now change the value in Design View, it does not affect the stored setting. It will return "This is a new test". The Scope of the Value is set to "User" of course, so that it can be changed during runtime.

What do I have to change so that the settings-Design-View stays updated. And where, if not in the settings.settings file, is the Value "This is a new test" stored?

Upvotes: 0

Views: 535

Answers (1)

Ruben2776
Ruben2776

Reputation: 60

I can't comment, so I'm posting this as an answer, but the updated settings are stored in a text file C:\Users\<username>\AppData\Local\<company_name>\<app_name>randomcharacters\1.0.0.0\user.config

You can programmatically get the path with

public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel)
{
    try
    {
        var UserConfig = ConfigurationManager.OpenExeConfiguration(userLevel);
        return Path.GetDirectoryName(UserConfig.FilePath);
    }
    catch (ConfigurationException e)
    {
        return e.Filename;
    }
}

Not sure how to answer the designer thing or if this is what you're after, but maybe it helped you.

Upvotes: 1

Related Questions