views:

140

answers:

2

Hi, I would like to maintain a list of all of the strings entered into a ComboBox across all uses of an application on a given PC, for use as the AutoCompleteSource for that ComboBox, i.e., I enter in "Fred" in the ComboBox, commit the data, close the application, reopen the application, reopen the ComboBox, type "F", receive the suggestion "Fred".

Assuming I already have in place code to create and maintain such a list in memory and add new elements to it as they are entered into the ComboBox, etc., what do you suggest as the best way to save/load this data in between sessions?

Possible complicating factors: This application will be deployed via OneClick deployment, and will search for updates online every time the application starts. I would prefer that if the application updates, the list still exists after the update has completed.

Thanks for your help.

+2  A: 

Depending on your access level, storing them in a flat file seems the easiest choice.

  • To read the list of options, read the file and return an empty list if it isn't there.
  • To add an item, create the file if it isn't there and then append the option.

That means you don't send an empty file with your updates, so the data survives.

It appears that you could put the file in the Data Directory or use Isolated Storage.

MarkusQ
Hi, can you just confirm for me where you are suggesting I store this file; whether that is in some location set by myself, or just in the application directory. Thanks.
Frosty840
I'd say /var/app_name, but I'm a *nix guy. Don't you MS Windows guys have a place where applications can put their files? I'd have thought that was known art by this point.
MarkusQ
ClickOnce deployments stick their files in some ghastly, generated alphanumeric hell. It's a special installation method provided by some part of the .net framework, largely not under the control of the programmer. That's why I'm slightly cagey about storing any files directly in the app folder.
Frosty840
Both the Data Directory and Isolated Storage look like good options.
MarkusQ
A: 

I would simply use the built in User Settings (My Project > Settings > Pick "User" for the scope of the setting); they are extremely easy to retrieve and update. And although I haven't done extensive testing, I believe they remain through application updates.

Does your application use a database? If so, that would be another option for permanent storage.

Edit
If you decide to go with the User Settings option, here is a new question that addresses an issue with those settings and ClickOnce.

whatknott