Application configuration?
-
I am new to C#. I am developing a small windows application to train myself with. I faced an issue and can't figure out a good approach to it. My application needs a few configuration settings that shall be available for altering from users interface. I can build a form etc. but the problem is that I don't know how to keep custom settings. I tried application configuration file, defining a custom section and using IDictionary class instance for reading them. Well, I can read them but can't save them as they only get saved in System.Collections.IDictionary and don't get saved in the application config file. Is there any simple way to arrange custom configuration and read-write it? Can someone share a simple understandable example of it? I hope I explained it clear enough. Thank you all.
-
I am new to C#. I am developing a small windows application to train myself with. I faced an issue and can't figure out a good approach to it. My application needs a few configuration settings that shall be available for altering from users interface. I can build a form etc. but the problem is that I don't know how to keep custom settings. I tried application configuration file, defining a custom section and using IDictionary class instance for reading them. Well, I can read them but can't save them as they only get saved in System.Collections.IDictionary and don't get saved in the application config file. Is there any simple way to arrange custom configuration and read-write it? Can someone share a simple understandable example of it? I hope I explained it clear enough. Thank you all.
-
-
I am new to C#. I am developing a small windows application to train myself with. I faced an issue and can't figure out a good approach to it. My application needs a few configuration settings that shall be available for altering from users interface. I can build a form etc. but the problem is that I don't know how to keep custom settings. I tried application configuration file, defining a custom section and using IDictionary class instance for reading them. Well, I can read them but can't save them as they only get saved in System.Collections.IDictionary and don't get saved in the application config file. Is there any simple way to arrange custom configuration and read-write it? Can someone share a simple understandable example of it? I hope I explained it clear enough. Thank you all.
The .config file is just an XML file, so use the
System.Xml
namespace elements to append/insert/delete your settings. Note that this will not update your configuration options while the process is running. For information on how to do that, search the comments for this forum for keywords likeAppDomainSetup
because I've already covered how to do this a couple times. Of course, you could always update your settings in the running, cached instance if you provide an instance property for your configuration section object (which theIConfigurationSectionHandler
implementation creates) and update your UI accordingly.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
I am new to C#. I am developing a small windows application to train myself with. I faced an issue and can't figure out a good approach to it. My application needs a few configuration settings that shall be available for altering from users interface. I can build a form etc. but the problem is that I don't know how to keep custom settings. I tried application configuration file, defining a custom section and using IDictionary class instance for reading them. Well, I can read them but can't save them as they only get saved in System.Collections.IDictionary and don't get saved in the application config file. Is there any simple way to arrange custom configuration and read-write it? Can someone share a simple understandable example of it? I hope I explained it clear enough. Thank you all.
Look at XML serialization. You can create an xml file that contains your app settings. You would simply 1. open a file stream 2. create xml formatter 3. serialize the settings you choose to the xml file. Take a look at serialization. You could use the .config file but this is read only, therefore you cannot create a user interface to modify it.
-
Look at XML serialization. You can create an xml file that contains your app settings. You would simply 1. open a file stream 2. create xml formatter 3. serialize the settings you choose to the xml file. Take a look at serialization. You could use the .config file but this is read only, therefore you cannot create a user interface to modify it.
And if the config file contained other stuff not for his section? This would NOT be a good idea because the other
IConfigurationSectionHandler
implementations provided in the .NET BCL do not use XML serialization. XML Serialization would wipe out the file and create a new one (based on your stream preferences).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
I am new to C#. I am developing a small windows application to train myself with. I faced an issue and can't figure out a good approach to it. My application needs a few configuration settings that shall be available for altering from users interface. I can build a form etc. but the problem is that I don't know how to keep custom settings. I tried application configuration file, defining a custom section and using IDictionary class instance for reading them. Well, I can read them but can't save them as they only get saved in System.Collections.IDictionary and don't get saved in the application config file. Is there any simple way to arrange custom configuration and read-write it? Can someone share a simple understandable example of it? I hope I explained it clear enough. Thank you all.