Take the 2-minute tour ×

I am trying to read and write into app.config file of user-settings. I found a snippet of a code for working with confige file. I finally got it compiling and running, but it absolutely seems to be doing nothing to the App.config file.

Here is the code:

Method MainForm1.Button1.Click(sender: System.Object; e: System.EventArgs);
config  : System.Configuration.Configuration;

It is compiling without any errors, but I don't know if it is doing anything.

Is there anything wrong with the code? I need to be able to write/read a section and write/read a key/value. Thanks in advance.

UPDATE: Instead of using ConfigurationManager, I simply use Properties.Settings.Default. However, I am having bit of a problem writing into it and reading back from it, although program complies with without any errors and the code seems simple.

How do you read and write to Properties.Settings.Default from within your code?

share|improve this question
See this stack overflow answer: stackoverflow.com/questions/1157378/… –  Greg ''Wildman'' Finzer Aug 16 '11 at 18:43

1 Answer 1

up vote 1 down vote accepted

Maybe you're looking at the wrong file? The app.config you have in your solution will be copied to YourProgramFile.exe.config in the bin/Debug or bin/Release folder. When running your program it will update this file, not the app.config file in your solution.

Then perhaps you also should check write permissions on your application folder. Normally (Win Vista, Win 7) the User executing an application does not have write permissions in the Program Files folder where your application should reside, so updating the .config will most probably fail due to the lack of write permissions. This is even more true for Linux/Unix systems.

You should try to separate the elements you need to write and write an additional config file in a user-specific folder. You can take the defaults from the normal application config for that initially and just update the user-specific config file, this way you are not hindered by file permissions and every user can update their settings specifically.

share|improve this answer
Can you access the properties.settings value with this code - MainForm.Top := Properties.Settings.Default.item['MainFormTop']; –  ThN Aug 18 '11 at 12:45
Have a look at this article. Instead of storing top, left, height and width you better store Location (includes top+left) and Size (includes height + width): blogs.msdn.com/b/rprabhu/archive/2005/11/28/497792.aspx –  Sebastian P.R. Gingter Aug 18 '11 at 12:52

Your Answer


