Just now I came across ApplicationSettings in .NET WinForms that could handle complex types.
Currently I am using AppSettings in my ASP.NET WebForms which can handle only string.
Can I use ApplicationSettings in Webforms? If so how?
Just now I came across ApplicationSettings in .NET WinForms that could handle complex types.
Share
The basic idea:
In a different project, create classes that will hold your custom settings. For example:
Build the project containing the classes.
Go to the Settings tab in Project Properties. It will say that there is no settings file yet and ask if you want to create it.
Add a new settings file. In the type field select Browse and type the full class name. For example:
ClassLibrary.EndPointCollection. Save and rebuild the project.Hit the edit button for the setting value. (Note that this will not be available if the classes made in the earlier step are in the same project.) Use the UI to edit the settings.
If you open the web.config / app.config file, you will see something like this:
Finally, to read these settings from your code, simply use
The designer will have created, behind the scenes, the strongly-typed objects to allow the above to work. You can see the full details in the
Settings.Designer.csfile.Bottom line: you can make all kinds of custom type settings, as long as those settings have XmlSerializable or have type converter. This technique works on Web Applications, WinForms, WPF, Console Applications etc.