Extraneous characters appear when using a #Include on a text file

I am using VB 2005 to create a text file containing HTML code (which is then called from a SHTML file using an #include directive).

I generate the text using concatenation into a textbox.text field and then write it to disk using the VB command:

My.Computer.FileSystem.WriteAllText(filepath, TextBox1.Text,False)

The VB code:

TextBox1.Text = TextBox1.Text &"<font color=""000000"">"

TextBox1.Text = TextBox1.Text & x + 1 &"."

TextBox1.Text = TextBox1.Text &" <a href="""

etc.

When I display the file as a text file or as html in a browser it displays normally. When I use the #Include directive from the calling SHTML file it always returns three extraneous characters:??at the beginning of the displayed section.

Is this an issue with the VB-generated file or with the #Include directive? Any suggestions on how to prevent this?

Thanks!

[1556 byte] By [Xignal76] at [2007-12-23]
# 1

Sounds like a Text Encoding problem. What is the encoding on the files? I'm not sure what the WriteAllText writes as (presumably the default ANSI encoding). I would guess that your encodings are differents so that the browser sees a base encoding (UTF-8 probably) and interprets yout text file as such.

Or something like that. You need to pay attention to encodings (there's no such thing as plain ASCII).

SJWhiteley at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

WriteAllText() uses UTF-8 with BOM(Byte Order Mark) by default, the garbled characters is probably the byte order mark.

You can specify encoding in WriteAllText(), the following sample uses UTF-8 without BOM:

My.Computer.FileSystem.WriteAllText(filepath, TextBox1.Text, False, New System.Text.UTF8Encoding(False, True)

RyanTsai at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Ryan,

Thanks. That fixed the issue! The characters are gone.

Xignal76 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...