Problem solve Get help with specific problems with your technologies, process and projects.

Proper way to save configuration settings in the .NET environment?

In the past I have used .INI files or the Registry to save program configuration settings. What is the proper way to save configuration settings in the .NET environment?
As you might expect, the format is XML. To persist config settings such as properties of a form, we need to write to a config settings file. We use what are called dynamic properties.

Basically it goes like this:

You set up a dynamic property in the IDE for an object such as a form. The IDE creates an app.config file, an entry in the file for the property and adds code to the form to read the property from the file. You won't even break a sweat!

Now you're all set to read the config file and set the properties of your form, but there is more work to do to persist the properties dynamically.

To do that, you need to load the XML config file, walk the DOM to get the setting for each persisted property and then of course set the properties properly in the app. It is much easier than it sounds! In the MSDN help there is an article that has examples. Here is the URL for the online version.

To find it in your local version of MSDN search on "Creating Your Own Dynamic Properties."

Dig Deeper on Topics Archive

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.