-1

My Simple C# application contains a settings window. It actually prompts to set or reset password. Currently, I'm saving these preferences using database and displaying it accordingly during next logon.

I wonder if there could be an easy way to make the application remember those preferences when we open it for the next time.

Possible?

  • Not sure I understand your question? You mean you don't want to use your existing method of saving data in a database? What do you mean by "easy way?" – OldProgrammer Apr 01 '13 at 19:07
  • Your other option is to write it to the Registry, unless it will be used from multiple locations. – krillgar Apr 01 '13 at 19:07
  • @OldProgrammer: Sorry if I sounded confusing. I mean, there are quite a number of applications that doesn't have a back end support but still it saves preferences. How is it possible? (Understandable at least now?) – Navaneeth Krish Apr 01 '13 at 19:10
  • Very possible. See Visual Studio Application Settings: http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx – Peter Ritchie Apr 01 '13 at 19:10
  • @krillgar: I expected some answer like 'using configuration files'. (Just a weird guess that configuration files are used for this kinda purposes). Any suggestions? – Navaneeth Krish Apr 01 '13 at 19:11
  • Every .NET application has a configuration ( settings ) file that can be used for this purpose. I won't bother giving an example since you seem to be aware you should be using a configuration file. – Security Hound Apr 01 '13 at 19:22

3 Answers3

0

There are several ways to save preferences. You can use the built-in settings system through Properties.Settings.Default.yoursetting, you can use IsolatedStorage System.IO.IsolatedStorage, you could simply write a file to the application directory, you could save it in the registry by creating your own registry key. If you want something easy and simple, use the built-in settings by going to the solution explorer, open up the Properties folder and double-click on Settings.settings. Add the settings fields you want and you can access them through Properties.Settings.Default.yoursetting

jugg1es
  • 1,560
  • 18
  • 33
0

First thing to do is to have a clear understanding of your settings:

I will summarize how I usually categorize the options of an application.
I call them "DomainOptions", "MachineOptions" and "UserOptions"

DomainOptions are settings that define the behaviour of your application for every user and from whichever machine they run the app. These setting should obviously stored in the shared database and just a restrict number of users should be able to modify them (I.E. the uri of a web service, the shared folder for application data, the fixed tax value required by your local regulations and so on)

ApplicationOptions are settings that define the behaviour of your application when it is started by a specific machine. Think, for example to a machine that has VPN connection and need to authenticate before running the app. These settings could be stored in the app.config or other local storage (avoid at all cost the REGISTRY), but keep in mind that if you need to change these values at runtime you can't write them in the configuration files for the Application section because it is read only at runtime. In this case I suggest to write your own class to store some sort of XML files in your common application data directory (Environment.SpecialFolder.CommonApplicationData + yourappfolder)

UserOptions are settings that every user could personalize like colors, window positions, accessibility parameters and so on. These could easily stored through the configuration files (User section) because they are modifiable by every user. However, if you have also a class to store the ApplicationOptions it is trivial to implement a variation to store these settings in the Local application data. (Environment.SpecialFolder.ApplicationData + yourappfolder)

Steve
  • 213,761
  • 22
  • 232
  • 286
0

if it is a normal preference or if you don't really care if someone can just read the user's credentials and use it then it's fine to store it in a config file somewhere. You can also choose to encrypt the credentials and store it some where. However, I would rather use the windows' build in credential manager to store log on information the same way TFS does for example.

"Control Panel\All Control Panel Items\Credential Manager"

storing-credentials-in-credential-manager-service

Community
  • 1
  • 1
Willem Toerien
  • 250
  • 1
  • 3
  • 11