469,914 Members | 2,363 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,914 developers. It's quick & easy.

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(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?

Mar 31 '06 #1
3 3936
"mike" <mi*********@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/>

Apr 1 '06 #2
Thanks a lot as usual. That works perfectly.

Apr 1 '06 #3
Thanks a lot as usual. That works perfectly.

Apr 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by 00steve | last post: by
1 post views Thread by liuliuliu | last post: by
12 posts views Thread by =?Utf-8?B?RnJlZU5FYXN5?= | last post: by
reply views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.