473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 4111
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: 00steve | last post by:
Hi, I was wondering if anyone knew how to go about having a "save as HTML" option incorporated within a page. (I know the option is available from the file menu from within IE, but a client has...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
2
by: PB | last post by:
I need to enable users to download data in either an Excel file or an Access database (MDB file). The data they need exists in a SQL Server database: the XLS or MDB file does not actually exist...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi misters, I have an app.config (UTF-8 format file). I create an application winforms for changes and save configuration programatically. When I save changes the format file changes to ANSI ...
4
by: Mr Gray | last post by:
Hi Guys, My requirement is to scan an FTP directory for the presence of 4 files and if a specific file exists I can begin to GET those files, read the contents and save the contents into an SQL...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.