Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. converting string to html

converting string to html

Scheduled Pinned Locked Moved Web Development
csharphtmldatabase
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raghavendra Kodimala
    wrote on last edited by
    #1

    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

    L W E 3 Replies Last reply
    0
    • R Raghavendra Kodimala

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It depends how you display it. If you put it into a simple Textbox then it will be treated as such. If you want to display it formatted then you need to display it in a control that understands HTML.

      1 Reply Last reply
      0
      • R Raghavendra Kodimala

        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

        W Offline
        W Offline
        W Balboos GHB
        wrote on last edited by
        #3

        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.

        Ravings en masse^

        "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

        1 Reply Last reply
        0
        • R Raghavendra Kodimala

          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

          E Offline
          E Offline
          ellegonzalez
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups