ASP.NET - How to read the configuration from the web.config in this case

Asked By mostafa hamdy on 26-May-11 12:20 PM
hello all
I have some web application having some configuration in the web.config like the following:
<system.web>
  <profile>
    <properties>
    <add  name="English"  defaultValue="En" />
    <add  name="Frensh" defaultValue="Fr" />
    </properties>
  </profile>
  </system.web>
</configuration>
and I want to read properties from the  CS file , how can I read the properties using the  ConfigurationManager
please if any body get what I mean and can help me please send me or tell me about some url may help me in doing that
regards
Mostafa

Ravi S replied to mostafa hamdy on 26-May-11 12:32 PM
HI

follow this

Example 1:
 Collapse
<!-- This is an example Web.config file -->
<configuration>
    <appSettings>
            <add key="var1" value="SomeValue"/>
      </appSettings>
<configuration>
 
In this article, we will see how to read the configuration settings in the web.config using ‘javascript’.
 
Step 1: Create a new ASP.NET website. Add a button control to the Default.aspx.
 
Step 2: Right click the project > Add New Item > Web Configuration File
Add the following sample entry to the appSettings section in the web.config between the <configuration> tag as shown in the example 1:
 Collapse
<add key="var1" value="SomeValue"/>
 
Step 3: To read these entries using javascript, add the following script in the <head> tag of your Default.aspx page as shown below:
 
 Collapse
<head runat="server">
    <title></title>
    <script type="text/javascript">
    function ReadConfigurationSettings()
    {
        var k = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'
        alert(k);
    }
    </script>
</head>
 
Step 4: Call this function on a button click and display the values of the configuration settings:
 Collapse
<input type="button" value="Get" onclick="ReadConfigurationSettings();" />

Ravi S replied to mostafa hamdy on 26-May-11 12:33 PM
hi


refer the link ...


here are examples

http://www.dreamincode.net/forums/topic/38180-read-config-file-in-class-library/
Mihir Soni replied to mostafa hamdy on 26-May-11 01:14 PM
Hello,

Here is simply how to read/write web.config file

http://www.codeproject.com/KB/cs/readwritexmlini.aspx

Just scroll down there and get how to read particular attribute from the web.config file

hope this helps you

Thank you
Santosh Singh replied to Mihir Soni on 26-May-11 02:18 PM
Refer the link : http://www.alltechnicalfaqs.com/2011/05/how-to-store-database-connection-string.html

To understand web.config more better refer : http://www.alltechnicalfaqs.com/2010/04/understanding-aspnet-configuration.html

Regards,
Santosh
http://www.goodlivingguide.nethttp://www.goodlivingguide.net