save string var to html file without losing format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike

    save string var to html file without losing format

    Hi all,

    I am using StreamWriter class to save string var into html file but
    somehow when I open the html file all formats are lost. I want to keep
    all formats(spaces, newline and so on)For example, I have sFunc in
    below format(newline, spaces ...)
    ----------sFunc ----------------
    Function ABC(byval a as integer) as integer
    If a > 0 then
    x = 1
    else
    x = 2
    end if
    End Function
    -----------sFunc -----------------

    but when I save it to f.html file using streamwriter I see the
    following when I open the file by doubleclicking.
    -------------what i see----------------
    Function ABC(byval a as integer) as integerIf a > 0 thenx = 1elsex =
    2end ifEnd Function
    -------------what i see----------------


    Here is the code snippet
    -------------------------
    Dim sw As StreamWriter = New StreamWriter(Ap plication.Start upPath &
    "\f.htm", False)
    sw.AutoFlush = True

    sBody = m_sFuncBody
    sw.WriteLine("< html><head>")
    sw.WriteLine("< body>")
    sw.WriteLine(sF unc)
    sw.WriteLine("</body>")
    sw.WriteLine("</html>")
    sw.Close()
    -------------------------

    This may be html question but ..
    any suggestion?

  • Herfried K. Wagner [MVP]

    #2
    Re: save string var to html file without losing format

    "mike" <mikekimhome@gm ail.com> schrieb:[color=blue]
    > I am using StreamWriter class to save string var into html file but
    > somehow when I open the html file all formats are lost. I want to keep
    > all formats(spaces, newline and so on)For example, I have sFunc in
    > below format(newline, spaces ...)
    > ----------sFunc ----------------
    > Function ABC(byval a as integer) as integer
    > If a > 0 then
    > x = 1
    > else
    > x = 2
    > end if
    > End Function
    > -----------sFunc -----------------
    >
    > but when I save it to f.html file using streamwriter I see the
    > following when I open the file by doubleclicking.
    > -------------what i see----------------
    > Function ABC(byval a as integer) as integerIf a > 0 thenx = 1elsex =
    > 2end ifEnd Function
    > -------------what i see----------------[/color]

    Put the data inside a 'pre' element, for example. Additionally make sure
    characters like ">" are encoded correctly (">" -> "&gt;"). You can use
    'HttpUtility.Ht mlEncode' for this purpose.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • mike

      #3
      Re: save string var to html file without losing format

      Thanks a lot as usual. That works perfectly.

      Comment

      • mike

        #4
        Re: save string var to html file without losing format

        Thanks a lot as usual. That works perfectly.

        Comment

        Working...