Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html tags in app.config file in .net console application

Tags:

c#

I need to add html tags in app.config file in C# console application. I tried

<p>

but it dint work for me. Any ideas?

like image 526
Bala Avatar asked Feb 01 '11 04:02

Bala


People also ask

Which tag is present in ASP NET web config?

web> tag and the <appSettings> tag. (See the structure of web. config file in ASP.net 3.5.) The <appSettings> tag specifies application-wide settings using the <add> tag.


2 Answers

First, add a reference to System.Web to your project. Then, you can store your HTML by HTML encoding it. Simply call HttpUtility.UrlDecode() on your value stored in the config file.

Your config file:

<appSettings>
    <add key="HTML" value="&lt;p&gt;My paragraph&lt;/p&gt;"/>
</appSettings>

Your code:

string html = HttpUtility.UrlDecode(ConfigurationManager.AppSettings["HTML"]);
like image 190
wsanville Avatar answered Sep 28 '22 19:09

wsanville


Think you would actually want to

string html = HttpUtility.HtmlDecode(ConfigurationManager.AppSettings["HTML"]);

like image 38
user3591722 Avatar answered Sep 28 '22 20:09

user3591722