how to open .doc within vb.net?

  • Thread starter jabslim via DotNetMonster.com
  • Start date
J

jabslim via DotNetMonster.com

i have used this code(see below) to open .doc files using a cmd button, an
open dialog box, a microsoft textbox(in COM components) to display the .doc
file and a texbox to display the pathname of the file, it can open the .doc
file but the display is all messy and the characters and spaces wont appear
right.

is there another way to open a .doc file within the form in vb.net and make
it appear the same as the format when opening it in MS WORD?? (like the
paragraphs, pages, fonts, etc)
------------------------------------------------------------------------------
-------------------------------------------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog()
Dim file_doc As String
Dim di As New DirectoryInfo("c:\")

openFileDialog1.Title = "Please Select a File"
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "ms word files (*.doc)|*.doc"
openFileDialog1.ShowDialog()
file_doc = openFileDialog1.FileName.ToString()
TextBox1.Text = file_doc 'pathname


Dim fs As New FileStream(file_doc, FileMode.Open, FileAccess.Read)

Dim sr As New StreamReader(fs)

sr.BaseStream.Seek(0, SeekOrigin.Begin)

While sr.Peek() > -1
AxTextBox1.MultiLine = True
AxTextBox1.Text &= sr.ReadLine()
End While
sr.Close()

End Sub


------------------------------------------------------------------------------
 
A

Armin Zingler

jabslim via DotNetMonster.com said:
i have used this code(see below) to open .doc files using a cmd
button, an open dialog box, a microsoft textbox(in COM components)
to display the .doc file and a texbox to display the pathname of the
file, it can open the .doc file but the display is all messy and the
characters and spaces wont appear right.

is there another way to open a .doc file within the form in vb.net
and make it appear the same as the format when opening it in MS
WORD?? (like the paragraphs, pages, fonts, etc)

You don't know the file format of a .Doc file, consequently you can not
interpret the content. I don't think there is a public documentation
available. Even if it was, I guess you would have to read a lot in order to
be able to display what you want.


Armin
 
Z

zacks

i have used this code(see below) to open .doc files using a cmd button, an
open dialog box, a microsoft textbox(in COM components) to display the .doc
file and a texbox to display the pathname of the file, it can open the .doc
file but the display is all messy and the characters and spaces wont appear
right.

is there another way to open a .doc file within the form in vb.net and make
it appear the same as the format when opening it in MS WORD?? (like the
paragraphs, pages, fonts, etc)

The standard TextBox control cannot display anything but ASCII text.

Here is a link that may be useful to you. BTW, this was the second
link in a Google search for "microsoft word control for .net". Google
is your friend.

http://support.microsoft.com/kb/304643
 
C

Cor Ligthert[MVP]

The standard TextBox control cannot display anything but ASCII text.

Unicode text, ASCII is a codetable from the time even before the IBM PC.

(It was meant for 7 track papertape)

Cor
 
E

Egghead

Hi here,

Very very very lazy M$; there is no ture .Net webbroswer component yet??

--
cheers,
RL
i have used this code(see below) to open .doc files using a cmd button, an
open dialog box, a microsoft textbox(in COM components) to display the
.doc
file and a texbox to display the pathname of the file, it can open the
.doc
file but the display is all messy and the characters and spaces wont
appear
right.

is there another way to open a .doc file within the form in vb.net and
make
it appear the same as the format when opening it in MS WORD?? (like the
paragraphs, pages, fonts, etc)

The standard TextBox control cannot display anything but ASCII text.

Here is a link that may be useful to you. BTW, this was the second
link in a Google search for "microsoft word control for .net". Google
is your friend.

http://support.microsoft.com/kb/304643
 
J

jabslim via DotNetMonster.com

ive already seen and tried that, but it open the whole MS WORD inside the web
browser control. all i want is to view the file without the MS WORD's menu
bar, etc... and i want to make it only viewable, not editable.(i use msword
2007)
 
C

CMoya

If you don't want to use zack's suggestion of hosting MS Word as a
container, you can maybe get a little creative and "translate" the document
using Word itself behind the scenes. Word exposes a nice automation object
model. Add a reference to the Word object library (References -> Add ->
COM -> Microsoft Word 12 Object Library). Create an instance of the Word COM
object (Word.Application). Open the document. Save it As RTF or HTML in the
temp directory and then load it up in the RichTextBox or Webbrowser control.
This can all be done behind the scenes.

If you're worried about binding to a version of Word the user may or may not
have (Version 12 in this case), you can turn off Option Strict, remove the
"Reference" mentioned above, and automate the Word.Application object that
way. Word's object model is largely backwards compatible and doesn't change
a whole lot between versions.

I dunno. Just food for thought.
 
W

Wolf Saenger

Hi jabslim

can't you use the word api.
There are hell of samples how to read and show *doc.

Check out the M$ Pages.

regards
Wolf
 

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