简体   繁体   English

.net 控制台应用程序中 app.config 文件中的 html 标签

[英]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="&lt;p&gt;My paragraph&lt;/p&gt;"/>
</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.

相关问题 在 Visual Studio for mac 中为控制台应用程序添加 app.config 文件 - Add app.config file for console application in Visual studio for mac 如何在控制台应用程序中将值永久写入app.config文件? - How to write value to app.config file permanently in a console application? 控制台应用程序中的 App.Config 文件 C# - App.Config file in console application C# 在App.config文件控制台应用程序中保护部分 - Protecting Section in App.config file Console Application 如何在控制台应用程序中添加App.Config文件 - How to add App.Config file in Console Application 在 app.config 中为控制台应用程序存储值 - storing value in app.config for console application 可以在app.config中模拟控制台应用程序吗? - Possible to impersonate in app.config for console application? 如何通过 Z240AA3 控制台中的 App.config 文件控制 static html 页面的动态 html 表的样式? - How to control styling of a dynamic html table of a static html page through App.config file in a c# console application? 如何在.NET应用程序中使用自定义配置文件或app.config - How to use custom configuration file or app.config in .NET application 如何在父控制台应用程序和ASP.NET Web应用程序之间共享app.config - How to share app.config between parent console application and ASP.NET web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM