[英]html tags in app.config file in .net console application
I need to add html tags in app.config file in C# console application.我需要在 C# 控制台应用程序的 app.config 文件中添加 html 标签。 I tried我试过了
<p>
but it dint work for me.但它对我有用。 Any ideas?有什么想法吗?
First, add a reference to System.Web
to your project.首先,向您的项目添加对System.Web
的引用。 Then, you can store your HTML by HTML encoding it.然后,您可以通过HTML 编码来存储您的 HTML。 Simply call HttpUtility.UrlDecode()
on your value stored in the config file.只需对存储在配置文件中的值调用HttpUtility.UrlDecode()
。
Your config file:你的配置文件:
<appSettings>
<add key="HTML" value="<p>My paragraph</p>"/>
</appSettings>
Your code:您的代码:
string html = HttpUtility.UrlDecode(ConfigurationManager.AppSettings["HTML"]);
Think you would actually want to认为你真的想要
string html = HttpUtility.HtmlDecode(ConfigurationManager.AppSettings["HTML"]);字符串 html = HttpUtility.HtmlDecode(ConfigurationManager.AppSettings["HTML"]);
If its ok you can create a separate HTML file and read the content using C# code.如果没问题,您可以创建一个单独的 HTML 文件并使用 C# 代码读取内容。 Then use that variable for your code.然后将该变量用于您的代码。
Like below像下面
string htmdata = File.ReadAllText(@"D:\\Sendmail\\email.html"); string htmdata = File.ReadAllText(@"D:\\Sendmail\\email.html");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.