How can I access ConfigurationManager.AppSettings
in my Windows Forms Application?
The error message reads: The name 'ConfigurationManager' does not exist in the current context.
it is a .net builtin mechanism to define some settings before the application starts, without recompiling. see msdn configurationmanager.
To access these values, there is one static class named ConfigurationManager, which has one getter property named AppSettings. We can just pass the key inside the AppSettings and get the desired value from AppSettings section, as shown below. When we implement the code given above, we get the output, as shown below.
ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.
Add the App. config file to your project. After creating a . NET Framework project, right-click on your project in Solution Explorer and choose Add > New Item. Choose the Application Configuration File item and then select Add.
Add a reference to System.Configuration.dll.
I've had this experience before where I had to go and add a reference to System.Configuration to be able to use this funcitonality.
Right click on your project in the solution explorer, select Add Reference then select the .Net tab (it should be selected by default), and select System.Configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With