Add html string in web.config

Today We needed to add an HTML string in the web.config. This string will be used in multiple methods as a replacement holder.
While html is just a simple table, it's content will be changed on the fly.
Here is what we ended up with in the appSettings section of the web.config

      <add key="html" value="&lt;table&gt;&lt;tr&gt;&lt;td&gt;{TOREPLACE}&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"/>

Here is how to use the code

var setting = ConfigurationManager.AppSettings.Get("html");
var content = setting.Replace("{TOREPLACE}", "New content");

Comments (3) -

Cool trick.
thanks for sharing

Property 'value' is not a ConfigurationElement.

Marionnette 2/17/2014 9:44:07 AM

Yeah ! Thanks !

Comments are closed