Gatt Posted February 5, 2010 Posted February 5, 2010 Ok so following on from this thread (http://www.edugeek.net/forums/coding/49638-c-button-delay-timer.html) How do I get C# to read settings from a configuration file (app.config?) that can be changed by the end user (ie the admin)
Gatt Posted February 5, 2010 Author Posted February 5, 2010 ok half way there - I now have an app.config file that holds the location of the file Unfortunately any changes to this file by an end user doesn't have any effect
powdarrmonkey Posted February 5, 2010 Posted February 5, 2010 Use the settings classes - look under Settings in your project properties, and it will generate a settings file and classes for you.
Gatt Posted February 5, 2010 Author Posted February 5, 2010 Tried that - but same problem - in fact there was no sign of a settigns file that could be editted
powdarrmonkey Posted February 5, 2010 Posted February 5, 2010 It should appear next to the .exe when you build. Make sure they are application settings and not user settings.
Gatt Posted February 5, 2010 Author Posted February 5, 2010 nope - the app.config does but not via properties -> settings (aka Settings.settings in VS) But any changes to app.config doesnt take effect until i rebuild the solution.
Andy-3-16 Posted February 5, 2010 Posted February 5, 2010 You need to go to your web.config file... if you haven't got one add a Web.config file. Make sure you've got an section like this:- Then add a reference to System.Net.Configuration and in code use:- string setting = System.Net.Configuration.ConfigurationManager.AppSettings["settingName"] or something like that. Good luck.
Gatt Posted February 5, 2010 Author Posted February 5, 2010 Ok got the Propect Properties -> Settings working and updating app.config But still cant change the value after its built - even though the scope is for a user... So, somehow the application isn't re-reading the app.config when its run..
localzuk Posted February 5, 2010 Posted February 5, 2010 Web.settings is only for web settings... App.config is a file that when you're building, you shouldn't edit directly from what I've seen - Visual Studio doesn't like it. The way I do it is - do all my original settings setting via the settings window in visual studio, reference them via Properties.Settings.Default.blah (remembering to save them if changing them during runtime via the program itself), and then editing the blah.exe.config file by hand if needs be, outside runtime. The app.config gets turned in to blah.exe.config when you rebuild - so any changes you make to app.config will only get transferred to the blah.exe.config when you rebuild. 1
Gatt Posted February 5, 2010 Author Posted February 5, 2010 You need to go to your web.config file... if you haven't got one add a Web.config file. Make sure you've got an section like this:- Then add a reference to System.Net.Configuration and in code use:- string setting = System.Net.Configuration.ConfigurationManager.AppSettings["settingName"] or something like that. Good luck. Thats pretty much what I have now - except its app.config - since this isnt a web application I'm making.. When I build the application it reads the value from app.config as it should, but doesnt change if app.config is edited post build
Gatt Posted February 5, 2010 Author Posted February 5, 2010 Web.settings is only for web settings... App.config is a file that when you're building, you shouldn't edit directly from what I've seen - Visual Studio doesn't like it. The way I do it is - do all my original settings setting via the settings window in visual studio, reference them via Properties.Settings.Default.blah (remembering to save them if changing them during runtime via the program itself), and then editing the blah.exe.config file by hand if needs be, outside runtime. The app.config gets turned in to blah.exe.config when you rebuild - so any changes you make to app.config will only get transferred to the blah.exe.config when you rebuild. OK that makes abit of sense - but how do i save them?
localzuk Posted February 5, 2010 Posted February 5, 2010 OK that makes abit of sense - but how do i save them? Properties.Settings.Default.Save(); 1
Gatt Posted February 5, 2010 Author Posted February 5, 2010 Cheers - will look at getting that added in
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now