Dynamic Configuration Setting Values

For example you need to add some parameters in an url which is stored in your configuration file. By using the String.Format Method, it’s possible to add format items in the setting value. In code you can replace those format items with the propper string values.

<add key="url" value="http://www.google.com/search?hl={0}&q={1}"/>
String url = String.Format(ConfigurationManager.AppSettings["url"], "en", "visual studio");

The result of this url will be: “http://www.google.com/search?hl=en&q=visual studio”

Advertisements

Comments are closed.

%d bloggers like this: