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

Reading Text

P: n/a
I am using a StreamReader to read text from an HTML file and display it as
part of a page in a Label Control. Buy it is not displaying characters as:
, , , etc.

Please Help.

Thanks
Nov 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
This is the code I am using:

Dim sr As StreamReader = File.OpenText(SourceHTMLFile)

Dim input As String

input = sr.ReadToEnd

lblContent.Text = "<BR><BR>" & input

sr.Close()

I know that reads UTF, how can I read it so it displays all the characters?

Thanks

"T Cordon" <tc******@hotmail.com> wrote in message
news:ez**************@TK2MSFTNGP10.phx.gbl...
I am using a StreamReader to read text from an HTML file and display it as
part of a page in a Label Control. Buy it is not displaying characters as:
, , , etc.

Please Help.

Thanks

Nov 18 '05 #2

P: n/a
In article <ez**************@TK2MSFTNGP10.phx.gbl>, tc******@hotmail.com
says...
I am using a StreamReader to read text from an HTML file and display it as
part of a page in a Label Control. Buy it is not displaying characters as:
, , , etc.


Make sure you're propely encoding the data for HTML by using the
HttpUtility.HtmlEncode method.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #3

P: n/a
The HTML file is created using Word, and by itself it is displayed
correctly.

Guess the problem is reading it or what else can it be?

Thanks
"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <ez**************@TK2MSFTNGP10.phx.gbl>, tc******@hotmail.com
says...
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: , , , etc.


Make sure you're propely encoding the data for HTML by using the
HttpUtility.HtmlEncode method.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 18 '05 #4

P: n/a
In article <#W**************@TK2MSFTNGP10.phx.gbl>, tc******@hotmail.com
says...
The HTML file is created using Word, and by itself it is displayed
correctly.


Are you stripping out the "header" information out of the top of the
HTML file Word creates? Things such as "<HTML>" and "<HEAD>", etc...?

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #5

P: n/a
No, how could I do that?

This seems to work now, and gets all the chars:

Dim str1 As FileStream = File.OpenRead(SourceHTMLFile)

Dim BA() As Byte = New Byte() {}

Dim input As String

ReDim BA(str1.Length)

Dim x As Integer

For x = 1 To str1.Length

input &= Chr(str1.ReadByte)

Next

lblContent.Text = "<BR><BR>" & input

str1.Close()
Does this seem right?

Thanks Again

"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <#W**************@TK2MSFTNGP10.phx.gbl>, tc******@hotmail.com
says...
The HTML file is created using Word, and by itself it is displayed
correctly.


Are you stripping out the "header" information out of the top of the
HTML file Word creates? Things such as "<HTML>" and "<HEAD>", etc...?

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 18 '05 #6

P: n/a
I believe your going the long way round to get a string from your file.
Here's a simpler example:

Dim sr As StreamReader
Try
sr = New StreamReader(SourceHTMLFile)
lblContent.Text = "<BR><BR>" & sr.ReadToEnd()
Catch
Finally
If Not IsNothing(sr) Then sr.Close()
End Try

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"T Cordon" <tc******@hotmail.com> wrote in message
news:O8*************@tk2msftngp13.phx.gbl...
No, how could I do that?

This seems to work now, and gets all the chars:

Dim str1 As FileStream = File.OpenRead(SourceHTMLFile)

Dim BA() As Byte = New Byte() {}

Dim input As String

ReDim BA(str1.Length)

Dim x As Integer

For x = 1 To str1.Length

input &= Chr(str1.ReadByte)

Next

lblContent.Text = "<BR><BR>" & input

str1.Close()
Does this seem right?

Thanks Again

"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <#W**************@TK2MSFTNGP10.phx.gbl>, tc******@hotmail.com
says...
The HTML file is created using Word, and by itself it is displayed
correctly.


Are you stripping out the "header" information out of the top of the
HTML file Word creates? Things such as "<HTML>" and "<HEAD>", etc...?

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele


Nov 18 '05 #7

P: n/a
In article <O8*************@tk2msftngp13.phx.gbl>, tc******@hotmail.com
says...
No, how could I do that?

This seems to work now, and gets all the chars:

Dim str1 As FileStream = File.OpenRead(SourceHTMLFile)

Dim BA() As Byte = New Byte() {}

Dim input As String

ReDim BA(str1.Length)

Dim x As Integer

For x = 1 To str1.Length

input &= Chr(str1.ReadByte)

Next

lblContent.Text = "<BR><BR>" & input

str1.Close()
Does this seem right?


Your original post showed you using "ReadToEnd" and this one you're
reading a byte at a time and concatenating. Which one are you using?

In any case, the problem could be an encoding issue. If the file is
produced from Word, it may be Unicode. You should ready the file into a
byte array (like you did in the first example) then try using
System.Text.Encoding.Unicode.GetString() on the byte array.

If that doesn't work, try one of the other encoding classes like UTF8.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #8

P: n/a
Whoa, now, Patricia! If it is a Word file, it is binary, not Unicode! The
only way to open and read a Word file is to use the Word COM interface.

I assumed that she's reading some type of HTML document, because her
variable is called "SourceHTMLFile". If so, it is pure text, and reading it
into a byte array is not only unnecessary, but may be causing the problem
she's describing, as a byte array is NOT text, but binary.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <O8*************@tk2msftngp13.phx.gbl>, tc******@hotmail.com
says...
No, how could I do that?

This seems to work now, and gets all the chars:

Dim str1 As FileStream = File.OpenRead(SourceHTMLFile)

Dim BA() As Byte = New Byte() {}

Dim input As String

ReDim BA(str1.Length)

Dim x As Integer

For x = 1 To str1.Length

input &= Chr(str1.ReadByte)

Next

lblContent.Text = "<BR><BR>" & input

str1.Close()
Does this seem right?


Your original post showed you using "ReadToEnd" and this one you're
reading a byte at a time and concatenating. Which one are you using?

In any case, the problem could be an encoding issue. If the file is
produced from Word, it may be Unicode. You should ready the file into a
byte array (like you did in the first example) then try using
System.Text.Encoding.Unicode.GetString() on the byte array.

If that doesn't work, try one of the other encoding classes like UTF8.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 18 '05 #9

P: n/a
My deepest apologies, Patrick, for calling you "Patricia" by accident! :-}

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
Nov 18 '05 #10

P: n/a
In article <O6**************@TK2MSFTNGP12.phx.gbl>,
ks******@takempis.com says...
My deepest apologies, Patrick, for calling you "Patricia" by accident! :-}


No biggie. I've been called worse!! :)

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.