change the settings file items in .Net console application

1.8k views Asked by At

I tried to change some setting witch my console application want to set and use on every execution.

1)added a .settings file named InputSettings.

2)added two items with Scope:User.

3)change the code like this:

private projAPI.InputSettings settings = new InputSettings();
settings.publishEndDate = DateTime.Now;
settings.Save();

It doesn't make any changes in setting file, but everytime I run a project, setting is changed when I trace that line.

Is there any mistake I had?

1

There are 1 answers

3
Suigi On

User settings are stored in a different file. See this question:

If you want to get to the path programmatically, you can do it using the Configuration Management API (you need to add a reference to System.Configuration.dll). For example, here is how you can get the local user.config file path:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Console.WriteLine("Local user config path: {0}", config.FilePath);

MSDN Documentation lists a few examples on how to use application and user settings.

For example How To: Write User Settings at Run Time with C#

Access the setting and assign it a new value as shown in this example:

Properties.Settings.Default.myColor = Color.AliceBlue;

If you want to persist the changes to the settings between application sessions, call the Save method as shown in this example:

Properties.Settings.Default.Save();