Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all...

This question might be a long one not sure. I am trying to do something that I'm sure it done by a lot of people of a regular basis but I have no idea where to start...

I have a series of controls on a form that setup a configuration for another section of the program (this bit is not so important for my question). The controls are standard list boxes, text boxes, combo boxes etc etc...

I need to save this configuration for future use, or load old ones. What is the best way of going about this? It would be nice if it was an editable and familiar format such as XML. Can you directly map .Net controls to an XML schema or something equally jazzy?

Not looking for masses of code here, just some fingers pointing me in the right directions, I would like to learn!
Posted
Comments
JasonD_S 26-Oct-10 8:43am    
I have found a solution to my problem which is much simpler than all the nonsense I thought I might want before. I have decided to go with a straight 'serialize' of the data I need into an XML format. Something I have used in the past, but it totally slipped my mind when I approached this problem (a bit rookie, but it's still early days for me). Will make it easier to handle my config/setup at runtime.

This was a really useful exercise and I have learned a lot about .Net and app.config which I am going to use, now and in the future. Many thanks to John for your answers!
Tarun.K.S 27-Oct-10 13:33pm    
hmm serialization is a good approach.

Create a Settings object, and call Save on it when it's appropriate. I believe it will automatically load when you start the app if it sees that a file is already there.
 
Share this answer
 
Comments
Tarun.K.S 25-Oct-10 10:50am    
well john would you please elaborate the procedure for doing that. Even i want to do the same thing that Jason wants, to store some particular information in lets say XML. One way could be making XML's build action to be Content File in WPF and specifyin the copy to output as Always. But i wanna know how to do it in your way? i want that XML to be editable also! Thanx!
JasonD_S 25-Oct-10 11:25am    
The ability to modify the output/input of the saved settings/config file outside of the app is quite important. Which is why I wanted to use XML.

Have done a bit of reading and it looks like I will have to have an XMLWriter/Reader class that does a direct copy of the data on my forms into raw XML. Looks a bit manual and fiddly... what I need are a couple of simple examples I can build from really.
I wroite a couple of articles about saving/loading config files:

Overriding App.Config Settings for Multiple Objects[^]

and...

Share User Settings Between Applications[^]

The underlying class used in those articles provides some generic validation on loaded settings. Just use the sample projects as a guide for how you might go about it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900