Question

coding my app I noticed I need to save somehow datas from textboxes and comboboxes into a file, so I can retrieve this infos anytime I want.
For instance, I have a comboBox where I can choose between all available Com ports. I would like to save the selected item, thus I can run my app and do all the stuff without choosing it again because it is already saved.
I don't know how many ways this task can be accomplished, but I found two of them I think they can fit my coding:

  • XML
  • app.config

Using an XML file, I can open a XmlTextWriter, save all the data needed and open it using a XmlTextReader to retrieve informations. I can do the same thing adding an app.config file into my project and save my datas into it.

I'm not that experienced, so I can't find so much difference between them. To me, they are both valid ways to save datas into a file.
According to your opinion/experience, which is the best way to pursue this task? Are they the same or one of this suits better for this kind of application?
Thank you so much!

Was it helpful?

Solution

The XML file approach requires you to write more code and you'll need to store the path to the XML file somewhere in your app. However, it does allow you to have multiple XML files that you can choose between, which is useful if you need to switch your app between different configurations.

The app.config approach has lots of config management code already written (ConfigurationManager and/or Properties.Settings etc) so is easier and it allows each user to have their own settings created for them automatically when they install your app. However, you can't readily choose between different app.configs if that matters.

You can do both and store some settings in app.config and other settings in an XML file with the path to the XML file stored in app.config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top