Encoding help !

O

Oozle_Finch

Hello all,

I am trying to read from a Word document which is written in Japanese. I
have figured how to read a .txt document without problems, but when I read a
Word document the result comes out all garbled. I am posting the code that I
use below to read from the text files in hopes that someone can explain how
to use it for Word documents:

Dim fs As New FileStream("E:\DESKTOP\My_Japanese_File.doc",
FileMode.Open, FileAccess.Read)
'declaring a FileStream to open the file named *.doc with
"shift_JIS" encoding
Dim d As New StreamReader(fs, System.Text.Encoding.GetEncoding(932))
'creating a new StreamReader and passing the filestream object fs as
argument
d.BaseStream.Seek(10, SeekOrigin.Begin)
While d.Peek() > -1
'peek method of StreamReader object tells how much more data is
left in the file
RichTextBox1.Text &= d.ReadLine()
'displaying text from doc file in the RichTextBox
End While
d.Close()

Any help or guidance would be extremely appreciated !

Regards,
Jeremy
 
T

Tony Jollans

To read a Word document (prior to 2007) you must use Word, and Word itself
should handle the encoding. To access the document content you need to use
the Word Object Model.You can't read a Word document as a stream (well, you
can, but you have to be psychic to understand the result).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top