Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am developing an application where I need to keep track of multiple entries and keep them saved in the application for the next time. In short, I want to make a settings section for my application. Now, I have been trying out different things like Config File entries and app.config.
Can anyone guide me by suggesting me some good tutorial because I have already searched the internet but have found nothing to fulfill my demand.
Regards,
Farrukh Javeid

Moved from Answer by OP:
I think, I might have made a little mistake in explaining the problem. What I want to do is to save some information about the user that he can alter at anytime.
For example, I want to save the default username and password of the client but out of his muliple accounts, the user can select any of them and from so on that new entry will replace the previous one.
Thank you very much for your support friends.
Posted
Updated 25-Jan-11 12:27pm
v2

It's easy:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;
5) To write your setting:
Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();
 
Share this answer
 
Comments
farrukh.javeid 25-Jan-11 13:36pm    
I have tried this method as well put both the scope of the setting to User and Application level and saved it but it does not happen that way. The values are not saved.
GenJerDan 25-Jan-11 13:55pm    
Then you are having a different issue. The above code is correct. Looking for a file called "WhateverYourAppIs.exe.config" in the output directory of VS (Debug, hopefully) and see what's inside. It should contain the last changes you made to the settings. If not, then you are not calling the .Save() method in the right place or at all.
fjdiewornncalwe 25-Jan-11 18:26pm    
Moved from Answer by OP:
Actually, what I was thinking that I could use it like many times in a single session usage of the application. When I reopen it, after closing it, my settings from previous session would be saved. I hope you are understanding what I am trying to say.
OriginalGriff 26-Jan-11 6:32am    
Yes, I understand: and the above does just that - it is what it is there for.
farrukh.javeid 26-Jan-11 12:55pm    
Excuse me because it was my mistake. I have redone the code and it is working perfectly now.
Thanks!
An alternative solution:
Try SQLite
http://sqlite.phxsoftware.com/[^]

A lightweight database I think you will find suitable for your requirements. Use it for your local storage requirements.

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
JF2015 26-Jan-11 3:25am    
Good alternative.
If it is something simple, use what is already suggested. If you are after some complex set of values, use ConfigurationSection class to create your own custom configuration sections.
 
Share this answer
 
If the settings you want to save are related to things like Form.Location etc. then this[^] might help.

Now that I think about it, it would probably work for other things as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900