ConfigurationManager in Windows Form using Visual Studio 2010

Published on Thursday, September 15, 2011
c#

When you create a new Windows Forms application in Visual Studio 2010, and if you want to do something related config file, normally you will use ConfigurationManager namespace, for example:

// Get the AppSettings section.   
NameValueCollection appSettings =    ConfigurationManager.AppSettings;

However, when you input “ConfigurationManager” in code, you will find the Visual Studio 2010 display error which means you need to resolve for using some one namespace, normally we can right click on the text "ConfigurationManager" and get a “Resolve…” menu item, but you can not see it this time:

cfgMan00

Why?

The reason is Visual Studio did not automatically reference to System.Configuration library. we have to manually add it: Add reference to System.Configuration, the version is 4.0:

cfgMan01

Now you can use right click to get “Resolve…” menu item:

cfgMan02