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 1717
This is the code I am using:
Dim sr As StreamReader = File.OpenText(S ourceHTMLFile)
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******@hotma il.com> wrote in message
news:ez******** ******@TK2MSFTN GP10.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******@hotmai l.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.Htm lEncode 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.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com... In article <ez************ **@TK2MSFTNGP10 .phx.gbl>, tc******@hotmai l.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.Htm lEncode method.
-- Patrick Steele Microsoft .NET MVP http://weblogs.asp.net/psteele
In article <#W************ **@TK2MSFTNGP10 .phx.gbl>, tc******@hotmai l.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(S ourceHTMLFile)
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.ReadBy te)
Next
lblContent.Text = "<BR><BR>" & input
str1.Close()
Does this seem right?
Thanks Again
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com... In article <#W************ **@TK2MSFTNGP10 .phx.gbl>, tc******@hotmai l.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(So urceHTMLFile)
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******@hotma il.com> wrote in message
news:O8******** *****@tk2msftng p13.phx.gbl... No, how could I do that?
This seems to work now, and gets all the chars:
Dim str1 As FileStream = File.OpenRead(S ourceHTMLFile)
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.ReadBy te)
Next
lblContent.Text = "<BR><BR>" & input
str1.Close()
Does this seem right?
Thanks Again "Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message news:MP******** *************** *@msnews.micros oft.com... In article <#W************ **@TK2MSFTNGP10 .phx.gbl>, tc******@hotmai l.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******@hotmai l.com
says... No, how could I do that?
This seems to work now, and gets all the chars:
Dim str1 As FileStream = File.OpenRead(S ourceHTMLFile)
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.ReadBy te)
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.Enc oding.Unicode.G etString() 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.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com... In article <O8************ *@tk2msftngp13. phx.gbl>, tc******@hotmai l.com says... No, how could I do that?
This seems to work now, and gets all the chars:
Dim str1 As FileStream = File.OpenRead(S ourceHTMLFile)
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.ReadBy te)
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.Enc oding.Unicode.G etString() 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. 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 "char" with an ASCII code
in 0..127
I've searched the ANSI C++ standard, the internet and various text books,
but can't see how to workaround this one. I've tried wchar_t and wstring
without success.
But rather than spending lots of time on...
|
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 text is available until I
have read it... which seems to imply that multiple reads of the input
stream will be inevitable.
Now I can correctly find the number of characters available by:
|
|
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 listen up;
Reports, the way I look at them, all present data downwards, in this way;
TITLE
data
|
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()
{
OperatingSystem os = Environment.OSVersion;
AppDomain ad = Thread.GetDomain();
| |
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 server is on one line (\r\n at end) and
is formed as - each of
which is seperated by a space. Arguments with spaces in them are enclosed in
quotations.
So, I'm able to open a connection to the server. When I send a message to
|
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 errors. After reading the ole object
from db, I saved it to C: as file1.bmp and displayed on the web. But it can
not be displayed. After I manually sent the file to wordpad, it shows
|
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 fails. Second,
why the data reader is reading every other record. Here is all of the
source code for my little application followed by the contents of the
log file that it dumps out:...
|
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 to read text file
but could not get the data in correct format.
All columns are not coming in dataset and rows are messing up.
Suggestions please ???
|
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 column in SQL 2000. I know there's a Varchar(MAX) feature in
SQL2005, but my budget mocks me right now and I need to do it in SQL 2K.
Situation:
I'm building a resume DB, and for ease of input, I'd really like to be able
to use a single...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |