Ask the Expert

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?

    Requires Free Membership to View

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."

This was first published in June 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: