retrieving a value from app.config

  • Thread starter Thread starter Vincent Haakmat
  • Start date Start date
V

Vincent Haakmat

My appconfig has this line in it:
<appSettings>
<!--
The Location of the reports.
-->
<add key="ReportsLocation" value="C:\Reports\" />

However I am not able to retrieve this line value
my code to retrieve it is:
string
repname=System.Configuration.ConfigurationSettings.AppSettings.GetValues("ReportsLocation").ToString();
reports1.ReportName = repname + "SQL_VehSchedule.rpt";

the value returned is "System.String[]SQL_VehSchedule.rpt" not
"c:\Reports\VehicleSchedule.rpt"

What am I typing wrong ?

Regards,

Vincent
 
Vincent said:
My appconfig has this line in it:
<appSettings>
<!--
The Location of the reports.
-->
<add key="ReportsLocation" value="C:\Reports\" />

However I am not able to retrieve this line value
my code to retrieve it is:
string
repname=System.Configuration.ConfigurationSettings.AppSettings.GetValues("Re
portsLocation").ToString();
reports1.ReportName = repname + "SQL_VehSchedule.rpt";

the value returned is "System.String[]SQL_VehSchedule.rpt" not
"c:\Reports\VehicleSchedule.rpt"

What am I typing wrong ?

Use
System.Configuration.ConfigurationSettings.AppSettings["ReportsLocation"]
instead of GetValues().
 
Vincent,

Don't use the GetValues method. Rather, use the indexer, like this:

repname= (string)
System.Configuration.ConfigurationSettings.AppSettings["ReportsLocation"];

Also, you don't need to call ToString, as it will be a string when
returned to you. You just need to cast.

Hope this helps.
 
Back
Top