Link to home
Start Free TrialLog in
Avatar of ipjyo
ipjyoFlag for United States of America

asked on

How to read appSettings section from App.Config?

hi,

I have the below App.Config file in my project.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="Xml" value="C:\Files\ins.xml"/>
  </appSettings>
</configuration>

I am trying to get the value of key "Xml" as follows.

string xmlFile  = "";
xmlFile = ConfigurationSettings.AppSettings["Xml"];

But it is not showing the value when I tried to show the value in a messagebox.
I also imported the namespace "System.Collections.Specialized" still not working.

Any ideas please?
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ipjyo

ASKER

I imported System.Configuration namespace.
and then I tried the below statement and still not working. It is not giving any error message.
System.Configuration.ConfigurationManager.AppSettings["Xml"];


Thanks.
Avatar of ipjyo

ASKER

The target framework is 3.5 if that makes any difference.

Thanks
Avatar of tvPrasad
tvPrasad

Change the as below and try.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="XmlFileName" value="C:\Files\ins.xml"/>
  </appSettings>
</configuration>

 
   
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ipjyo

ASKER

This section was already there and generated automatically.

<?xml version="1.0" encoding="utf-8" ?>

Thanks.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ipjyo

ASKER

I tried

Properties.Settings.Default.Xml

but it is saying "The name 'Properties' does not exist in the current context". Also when I tried to type the above line, visual studio is not giving intellisense for the above line. I think I need to add some reference.

Thanks
Avatar of ipjyo

ASKER

It is working when I created a new project and tried the code.

It must have been something with some other code in my project.
sorry for the trouble.