Windows Develop Bookmark and Share   
 index > Windows Forms General > ConfigurationManager.AppSettings in UserControl's?
 

ConfigurationManager.AppSettings in UserControl's?

Hi,

I am creating a user control using VS2008 & .NET 3.5in which I would like to retrieveAppSettings from an app.config file. The following line of code works fine in a Windows Forms app, but not in a UserControl:

Code Snippet

string strLogFile = ConfigurationManager.AppSettings["LogFile"].ToString();

It complains that "ConfigurationManager" does not exist in the current context. I have included the appropriate using statement:

Code Snippet

using System.Configuration;

The user controlwill build & run ok if I substitute ConfigurationSettings for ConfigurationManager, but that is deprecated and returns null in any case, so it is moot.

Does anyone have any idea why I cannot use ConfigurationManager in a user control?

Thanks.

Dan

dhurwitz  Friday, August 08, 2008 7:42 PM

Make a manual reference to System.Configuration, then you will see:

System.configuration [notice the small c]

Then you are set.

See http://geekswithblogs.net/jbentley/archive/2005/07/03/45320.aspx

JohnGrove  Friday, August 08, 2008 10:36 PM

Make a manual reference to System.Configuration, then you will see:

System.configuration [notice the small c]

Then you are set.

See http://geekswithblogs.net/jbentley/archive/2005/07/03/45320.aspx

JohnGrove  Friday, August 08, 2008 10:36 PM

Thanks, this fixed it. But what a thing!
dhurwitz  Monday, August 11, 2008 2:13 PM

I know, I discovered this the hard way too.

JohnGrove  Monday, August 11, 2008 2:26 PM

You can use google to search for other answers

Custom Search

More Threads

• First class in application
• Logging and emailing errors
• INI File
• Strange IDE Behavior (breakpoints)
• SuspendLayout and Layout Event on a UserControl
• Radio Button getting checked when a tab is selected using the code
• Drawing an custom icon in the caption area of a form
• ODBC unknown problem
• isit possible to add reports column dynamically??
• Creating text output in a foreign language... possible?