-3

I m not getting answer for this question.M confused between the answers which i got on the internet while surfing?

1
  • means would you like to store some value for your aaplication. Jul 24, 2013 at 5:10

3 Answers 3

3

You can use the appSettings section in your web.config file to add custom Key/Value pairs to your applications.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>    
    <appSettings>
      <add key="MyConfiguration" value="SomeConfigValue" />
    </appSettings> 
</configuration>

For reading the settings from a web.config file you can do the following.

using System.Web.Configuration;

var myCofigValue = WebConfigurationManager.AppSettings["MyConfiguration"]

Or use the configuration manager directly for other type of applications

using System.Configuration;

var myCofigValue = ConfigurationManager.AppSettings["configFile"]

Some more reading

http://msdn.microsoft.com/en-us/library/system.configuration.appsettingssection.aspx http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx

0

The appSettings section of web.config is a good spot for custom configuration, like this:

<appSettings>
    <add key="customsetting1" value="Some text here"/>
</appSettings>

To read the value in this section of web.config, do this:

System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

if (rootWebConfig1.AppSettings.Settings.Count > 0)
{
    System.Configuration.KeyValueConfigurationElement customSetting = rootWebConfig1.AppSettings.Settings["customsetting1"];

    if (customSetting != null)
        Console.WriteLine("customsetting1 application string = \"{0}\"", customSetting.Value);
    else
        Console.WriteLine("No customsetting1 application string");
}
0

For settings of any which need to use into your application, there is one of option to use add key into config file as below:

<configuration>
       <appSettings>
        <add key="Culture" value="en-GB"/>
        <add key="Theme" value="blue"/>
    </appSettings>

     -------------------------
     -------------------------

</configuration>

You can get above information into your project by using

System.Configuration.ConfigurationManager.AppSettings["Culture"]

It should be help to you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.