?
Solved

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

Posted on 2007-08-10
4
Medium Priority
?
190 Views
Last Modified: 2013-11-07
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?
0
Comment
Question by:rmmarsh
4 Comments
 
LVL 22

Expert Comment

by:JimBrandley
ID: 19674508
If this is something like user preferences, I think the most common location is app.config.
0
 
LVL 1

Assisted Solution

by:LordHaze
LordHaze earned 400 total points
ID: 19674648
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 -
http://www.devx.com/dotnet/Article/27959/1954?pf=true
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.
0
 
LVL 7

Accepted Solution

by:
prosh0t earned 1600 total points
ID: 19674860
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


0
 

Author Comment

by:rmmarsh
ID: 19675912
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.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question