save string var to html file without losing format

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

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(Application.StartupPath &
"\f.htm", False)
sw.AutoFlush = True

sBody = m_sFuncBody
sw.WriteLine("<html><head>")
sw.WriteLine("<body>")
sw.WriteLine(sFunc)
sw.WriteLine("</body>")
sw.WriteLine("</html>")
sw.Close()
 
mike said:
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----------------

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