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 10 1664
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
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
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
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
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
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
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
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
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Suresh Kumaran |
last post by:
Hi All,
Does anybody know the sytax in VB.NET to write the
contents of a multiline text box to a text file?
Appreciate help.
Suresh
|
by: Phil Slater |
last post by:
I'm trying to process a collection of text files, reading word by word. The
program run hangs whenever it encounters a word with an accented letter
(like rôle or passé) - ie something that's not a...
|
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much...
|
by: Magnus |
last post by:
allrite folks, got some questions here...
1) LAY-OUT OF REPORTS
How is it possible to fundamentaly change the lay-out/form of a report in
access? I dont really know it that "difficult", but...
|
by: Sabin Finateanu |
last post by:
Hi I'm having problem reading a file from my program and I think it's from a
procedure I'm using but I don't see where I'm going wrong. Here is the code:
public bool AllowUsage()
{
...
|
by: JoKur |
last post by:
Hello,
First let me tell you that I'm very new to C# and learning as I go. I'm
trying to write a client application to communicate with a server (that I
didn't write). Each message from the...
|
by: dale zhang |
last post by:
Hi,
I am trying to save and read an image from MS Access DB based on the
following article:
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
Right now, I saved images without any...
|
by: Jason Kumpf |
last post by:
OK I've been staring at this code all day and still with everything I
have tried I cannot figure out two problems I am having. Once is why
the space limit for the directory I create in the code...
|
by: Amit Maheshwari |
last post by:
I need to read text file having data either comma seperated or tab seperated
or any custom seperator and convert into a DataSet in C# .
I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
|
by: ChrisFrohlich |
last post by:
ASP.NET 2.0 with Text DataTypes:
I've got a similar question going in the SQL group, but I was wondering if
anyone has successfully implemented reading/writing character data from a
Text datatype...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
| |