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

Posted on 2007-08-10
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?
Question by:rmmarsh
    LVL 22

    Expert Comment

    If this is something like user preferences, I think the most common location is app.config.
    LVL 1

    Assisted Solution

    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.
    LVL 7

    Accepted Solution

    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


    Author Comment

    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now