In c# how can I read the text from a file, then apply a setting from in my program.
Config.dat:
autoquit = true
Then if autoquit is true then it’ll automatically quit. I know there are built in settings but I would like to know how to convert the settings from within the project to a file & then load the settings when you start the program.
You want to add an
<appSettings>section to your configuration file.If you don’t have a config file, right click on your project, click ‘Add’, click ‘New Item….’ and selection application (or web) configuration file from the ‘General’ tab.
Add a setting to your configuration file:
and then in your code, something like
You’ll need to add a reference to
System.Configurationto access theConfigurationManagerclass.This is the standard, accepted way to store configuration settings. Do not create text files and read string values from them. You can store typed values in the settings section but if you do some research you’ll find out how to do that.