converting string to html
-
I am storing html string formatted in database. Now I want that string to be shown formatted but it's putting string as it is with tags. This is in C#. Good answer is appriciated
-
I am storing html string formatted in database. Now I want that string to be shown formatted but it's putting string as it is with tags. This is in C#. Good answer is appriciated
-
I am storing html string formatted in database. Now I want that string to be shown formatted but it's putting string as it is with tags. This is in C#. Good answer is appriciated
You need to think about what it is you're working with. The contents of your database record is just simple text. There's no reason, when displaying it, that it will be anything but exactly what is stored. If, on the other hand, that text is opened in a web browser (IE, FireFox, Chrome, etc.) then it will interpret the text (that is what browsers do) and display it with the context that you want. The browser does have to consider the text is coming from a website and isn't just a simple file that happens to have HTML in it by accident. It, too, will then just show the text. As a hint, the text will have to be part of a web page that the browser can open or opened within a webpage that's already on the browser.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
I am storing html string formatted in database. Now I want that string to be shown formatted but it's putting string as it is with tags. This is in C#. Good answer is appriciated
You can use the HttpUtility.HtmlEncode method: var htmlString = HttpUtility.HtmlEncode(user.Company); It's a method called HtmlEncode in the HtmlUtility class which takes a string parameter and encodes it into a Html-safe string.