By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

save string var to html file without losing format

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
Thanks a lot as usual. That works perfectly.

Apr 1 '06 #3

P: n/a
Thanks a lot as usual. That works perfectly.

Apr 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.