Home All Groups Group Topic Archive Search About

save string var to html file without losing format

Author
31 Mar 2006 11:21 PM
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()
-------------------------

This may be html question but ..
any suggestion?

Author
1 Apr 2006 12:09 AM
Herfried K. Wagner [MVP]
Show quote Hide quote
"mike" <mikekimh***@gmail.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Apr 2006 12:20 AM
mike
Thanks a lot as usual. That works perfectly.
Author
1 Apr 2006 12:21 AM
mike
Thanks a lot as usual. That works perfectly.