I'm working on a C# class library that needs to be able to read settings from the web.config
or app.config
file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application).
I've found that
ConfigurationSettings.AppSettings.Get("MySetting")
works, but that code has been marked as deprecated by Microsoft.
I've read that I should be using:
ConfigurationManager.AppSettings["MySetting"]
However, the System.Configuration.ConfigurationManager
class doesn't seem to be available from a C# Class Library project.
Does anyone know what the best way to do this is?
You must add to the project a reference to the System.Configuration assembly.
Try this:
In web.config should be next structure:
Im using this and it works well for me
Read From Config :
You'll need to add a reference to Config
Get Value with using following code :
string value = Properties.Settings.Default.keyname;
Save to Config :
Also, you can use formo:
Config:
Code:
Another possible solution: