When creating a Configuration object, it asks for a path to a config file... I keep getting an exception thrown for an invalid file path... What's a valid path? I've tried "config.config" and ".\config.config", but I can't think of anything else.
A:
The path would be in the Environment.CurrentDirectory
where the .EXE is residing in. If I am not mistaken, the app.config file when added to the project, and when the project gets built, it will generate an config file in the same place as where the .EXE was compiled to, usually bin\debug
or bin\release
, for an example, suppose the application name was foo.exe
, its related config file would be foo.exe.config
.
Hope this helps, Best regards, Tom.
tommieb75
2010-02-09 00:53:43
+2
A:
If this is for accessing your app.config file, you can use System.Configuration.ConfigurationManager
static class, i.e.
var setting = System.Configuration.ConfigurationManager.AppSettings["MySetting"];
Edit: You probably want something like this then:
var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // choose ConfigurationUserLevel value, or provide @"c:\path\to\some\exe\"
configuration.AppSettings.Settings.Add("test", "value"); // for new configs
configuration.AppSettings.Settings["test2"].Value = "somevalue"; // for modification of existing keys
c.Save(); // or choose save location
jeffora
2010-02-09 00:57:11
It's not, because I want to set the settings as well as reading from them.
Motig
2010-02-09 01:00:59
Updated answer - hopefully that helps
jeffora
2010-02-09 01:30:45