• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Where is the best place to store variables that may or may not be saved (users choice)

I have some program variables in a C# program that may or may not have content.  My question is:  where is the best place to store those variables, if, in fact, they are to be saved? (user's choice).  I have tried the registry which worked fine until someone ran the program on Vista, and that caused the program to crash due to authorization level.  I was thinking about Settings, but since I have about 30 of these that *might* be saved, I'm not sure that would be the right choice.  The other choice is a table, but then again, if it isn't used, it's just taking up resources.

Any other ideas?
2 Solutions
If this is something like user preferences, I think the most common location is app.config.
To use / save user prefrences under any Windows Application is with the Application Settings.  

If you're using Visual Studio .net Professional Edition you can access the application "Settings" under the application properties (Right click in solution Explorer).  From here you can Define your own custom Application Settings and define scope / etc...

To access your application settings use Properties.Settings.Default.SettingName

Check this out for details -
Keep in mind that you need to use .save() and changing things like build numbers can cause the system to create a new settings file.
you can store them in an xml file, .ini, or database.  Usually if i'm not using the registry I just keep a file in the application path that will hold all of them, and then you can read and write the settings on program open/close.  You can get the path of that file (if you decide to put it in the application path) like this:

System.AppDomain.CurrentDomain.BaseDirectory + "\\MyFile.ini", for example.

Note that keeping them in a text file instead of a database will give you much less overhead

rmmarshAuthor Commented:
Thank you both; I think I'm going to go with the xml file... the data is not often used and it's a lot simpler to just create an xml file.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now