Reputation: 12693
I am working on a Windows based desktop App and when the App starts up I need to store some small piece of data at somewhere.
The purpose is to share some data between the instances of the same App. Again, the size of the data is very very small, in this case,it is just a string.
I did some research and find out there are following options:
Now I am using the easiest one - #3. I am wondering how other people deal with the same problem? Any suggestions?
Thanks
Upvotes: 5
Views: 2706
Reputation: 6898
I use a combination of database for more secure and user specific data, such as usernames and scores (I'm creating a game), and the registry for more global settings.
Upvotes: 0
Reputation: 2434
I think the answer to your question of which approach to use will depend on the process you're using. If you're running more of an Agile process for your development I'd do the bare minimum during your iteration to get the settings stored and shared successfully between your Apps. As more requirements surface about what the applications need or possibly performance becomes an issue just re-design your solution to satisfy the new requirements.
However if you're following more of a Waterfall process for your development (big design up front) and if you're at all anticipating that your application's requirements will grow beyond what you currently know (and this obviously happens quite often) then I'd design and build a solution that has been known to work well in the past. Some sort of database engine, whether heavy weight like MySQL or Microsoft's SQL Server Or a lightweigher version like SQLite will provide a well structure mechanism to share data between multiple application.
Here is also another discussion on stackoverflow about whether to use SQLite or XML for settings.
Upvotes: 0
Reputation: 4914
The file system is the best place to persist data. If the settings are per user, store the files in the user's home folder. If the settings are shared between users, store the files in the shared data directory (this was C:\Program Files
last time I used Windows). You should create a subdirectory for your application in either of these locations.
A simple text file is good for a simple string.
A data interchange format such as json or yaml is good for a complex data structure.
A database, such as SQLite (normally stored in a .db file) is good for when you have to read and write data frequently to disk.
Upvotes: 1
Reputation: 797
If the data you want to store is not sensitive, it is fine to store it in a plain text file. Using %appdata% is more centralized, I like the idea.
Upvotes: 0
Reputation: 3121
You might be able to use the built in settings available to you within the C# project.
Here is a MSDN link on how to use the settings within a C# project.
If you need something more complex, a flat file might suit your needs as well.
Upvotes: 0
Reputation: 61497
Add 5: .net configuration model. You can set fields under project settings -> settings, those will be available in the namespace AssemblyName.Properties
in the Settings
object.
If you really need to do it on your own, I'd advise you to save those files in %appdata%\YourProgramName
. You can get the path via Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
.
Upvotes: 4