How to read app.config file

Ask general questions here.
masterpix
Posts: 1
Joined: Wed Mar 06, 2013 8:58 am

How to read app.config file

Post by masterpix » Wed Mar 06, 2013 9:17 am

Hi,

I have a problem to read app.config file as following.

This is my app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  	<startup useLegacyV2RuntimeActivationPolicy="true">
    	<supportedRuntime version="v4.0"/>
    	<supportedRuntime version="v2.0.50727"/>
  	</startup>
  	<runtime>
    	<enforceFIPSPolicy enabled="false"/>
  	</runtime>
	<appSettings>
		<add key="mySetting" value="hello"/>
	</appSettings>
</configuration>
and I try to read my config in user code module with following code.
void ITestModule.Run()
{
      Report.Info("My Setting=" + System.Configuration.ConfigurationManager.AppSettings["mySetting"]);
}
But it doesn't work, the report message just show "My Setting=" with blank value.
Do I miss anything on this?


I have used Ranorex 4.0 and setting the target framework to .NET 4.0 in project properties.

Regards,
Peerapat

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to read app.config file

Post by Support Team » Thu Mar 07, 2013 11:36 am

Hello,

You could try the following line to get the content (string array) of the app.config file:
string[] content  = File.ReadAllLines(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Regards,
Bernhard
.
Image