Can anyone offer any advice on how to go about setting up the ability for a program to allow a user to set or change configuration options?

I can create a form with certain options, but how do I store the selections? In a database? XML file? In the Registry?

Any help would, as usual, be much appreciated, but a solid explanation of the concept is what I'm really seeking, and if anyone can provide a link to a site where I can study the concept would be ideal.

What kind of program is this? A windows app or web app.
If it is a windows app, I would use an ini file (or xml if you want). Just write the configuration changes to it and then read it when program opens. I prefer to stay away from the registry unless absolutely necessary.

if this is a web app, you would probably need to either use a cookie or a database.

It's a windows app, and I'd lean toward an XML file myself, but I'm not sure how to implement that functionality. Am I correct to assume that reading the file would require some sort of parsing, or would the app just "understand" what it reads on startup because it wrote it?.

I don't know if I'm just storing a list of parameters and values, variables or something else. I also don't know what code I would write to even cause the app to read such a file (the functionality may be automated, but I just haven't found it yet). I'll of course keep digging, but I'll accept help!

I don't think it is automated.
You will need to create a file reader, read the file in and then parse it.

Here is a code snippet of something i was working on.

private string stringA;
private string stringB;
private string stringC;
OpenFileDialog fd = new OpenFileDialog();
			fd.ShowDialog();
			FileStream f= new FileStream(fd.FileName, FileMode.Open, FileAccess.Read);
			StreamReader sr = new StreamReader(f);
			string strTemp = sr.ReadLine();
			while(strTemp != null)
			{
				switch (strTemp)
			 {
					case("<optionA>"):
						stringA = sr.ReadLine(); //reads in the next line after opening tag and sets it to stringA
						sr.ReadLine(); // gets rid of the closing tag
						break;
					case("<optionB>"):
						stringB = sr.ReadLine(); //reads in the next line after opening tag and sets it to stringB
						sr.ReadLine(); // gets rid of the closing tag
						break;
					case("<optionC>"):
						stringC = sr.ReadLine(); //reads in the next line after opening tag and sets it to stringC
						sr.ReadLine(); // gets rid of the closing tag
						break;

			 }
				strTemp =sr.ReadLine();
						
			}
			sr.Close();

The xml file would need to look like:

<optionA>
true
</optionA>
<optionB>
false
</optionB>
<optionC>
true
</optionC>

hope this gets you started

i would also like to know how to do this....

Yeah, thanks campkev.
That's a good start; at least I can visualize the concept. I'll need to do a bit more study into file readers and parsing though.
As always, I'll try to post my progress so others who might be at the same level I am can benefit.

How to best manage configuration information will depend on your situation, but XML is not a bad way to go in many cases. You can create a Configuration class with all of your variables, then just serialize it to XML. It's simple.

Check out my article on this subject for more details and full code:

XML Configuration File Example

Cheers,
- Steve

How to best manage configuration information will depend on your situation, but XML is not a bad way to go in many cases. You can create a Configuration class with all of your variables, then just serialize it to XML. It's simple.

Check out my article on this subject for more details and full code:

XML Configuration File Example

Cheers,
- Steve

Thanks, I have looked at it and will spend some time going over it later this evening. Very helpful site, by the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.