tags:

views:

237

answers:

6

In my WinForms app, I have a few textboxes that the user typed some data into. I want to store the data, but I don't want to use a database. In my stone-age C++ days, I'd just use a .ini. Somehow, app.config doesn't seem like the right place to store this data, though.

What are my other options?

+7  A: 

I would say the .config file is the right place. Just be sure to use the User scopped area of the Settings.settings file rather than the Application scope.

This works well for simple data types and when you have fixed values that will need to be saved because you need to define what variables you want to store at design time. So if your textboxes are dynamically created and you don't know many values you need to store it is not very useful.

Using IsolatedStorage might be another good option. You can create your own file in any format you want (keeping any values you need) and store it to the local machine in "IsolatedStorage".

auujay
Even better answer! +1.
Workshop Alex
+3  A: 

You can create a folder somewhere on the disk and simply write a file in any suitable format (XML, plain text, your choice). You could for instance do this under the path pointed out by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) or Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).

Fredrik Mörk
You and me, we think the same. :-) +1, and good answer!
Workshop Alex
+1  A: 

I would look into isolated storage. It is easy to set up per-user. And since it requires only partial trust, it will work for any deployment scenario.

Check this introduction.

Tor Haugen
+1  A: 

Create a .config or other data file (e.g. xml) in the application data for the specific user.

use system.environment.specialfolder to get the ApplicationData folder, add a subfolder with your company name, within this a subfolder with your application name, within this your data file for this specific user. Thus,

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourCompany\YourApplication\YourData.config"

Workshop Alex
A: 

I believe the proper place to store user settings in WinForms 2.0 would be in the settings file (not the config file). Here's a quick article for explanation.

ftank99
+2  A: 

Depending on how many variables/data you're looking to save the app.config/settings file can be the ideal place.

Check out the Settings Tab in the Project properties and note that you can set both Application settings and User settings. Application settings affect the entire application. User settings are stored per user.

The section of the app.config that contains user settings will be saved to the user directory when they are saved and reincorporated when they restart the app.

Check this url for an introduction to Application/user settings on MSDN and also this SO url for a similiar question.:

You could also look into storing your familiar old .ini files in a per user .ini by checking out the Special Folders enum as per this url.

intermension