Reputation: 7963
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.
Upvotes: 1
Views: 1143
Reputation: 4159
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
Upvotes: 2
Reputation: 34592
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.
Upvotes: 0