Click here to Skip to main content
15,885,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my application I have 1 class library project and 1 app.config file.Now I want to access the app.config's app settings key value.eg.
HTML
<add key="test" value="Hi" />

now I am writing
C#
String str=System.Configuration.ConfigurationManager.Appsetting["test"].toString();

In one of the method of a class.
but it giving value null in the string.

can any one help me out how to access it.
My requirement is I have to put a folder path in the config file and I have to read it from my application.
Posted
Updated 22-Nov-16 21:43pm
v2
Comments
JF2015 29-Nov-11 0:30am    
Edited to add code formatting.
Nickos_me 29-Nov-11 1:36am    
I understand you right - you use library in you windiws app and want to get info from app.config of library? It's sipler to write this app setting data in application app.config, because Configuration manager use that one by default, and not from the library.

1 solution

try this code,

C#
string str = new AppSettingsReader().GetValue("test", typeof(System.String)).ToString();


hope it helps,

mark this as answer if it helps you
and dont' forget to vote ..


thanks
 
Share this answer
 
Comments
souravghosh18 29-Nov-11 1:28am    
Hi, Thanks for your response I got the error The key 'test' does not exist in the appSettings configuration section. but in the app.config file I write it.
<configuration><appsettings><add value="Hi" key="test">
D K N T H 29-Nov-11 1:41am    
please give me some details about it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900