• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

How do I display a file

I'm puzzled how to display a Word file on a window form.  I know I can create an instance of Word and display a file with Word, but all I want is a simple read-only window for the user to scroll through.  Is there a way to have an enlarged text box with a scroll bar for the user to look at a file?  That's all I really want (or something that would look like that).

Can you help?  Thanks.

0
vlvawter
Asked:
vlvawter
1 Solution
 
tsayCommented:
Hey,

you can read the wordfile as any other file with the StreamReader object. Then you can display it in a RichTextBox. You can play with the RichTextBox properties on how it should handle scrollbars etc. I'll provide you with an example code that reads a file called "file.doc" into a richtextbox on a form. Good luck with it.

----EXAMPLE CODE----
fs=New FileStream("file.doc",FileMode.Open,FileAccess.Read) 'file.doc can be, offcourse, any file you wish
'declaring a FileStream to open the file named file.doc with access mode of reading
Dim d as new StreamReader(fs)
'creating a new StreamReader and passing the filestream object fs as argument
d.BaseStream.Seek(0,SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions in a file, in this code, to
'the beginning
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()
----EXAMPLE CODE----
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
tsay...how could that possibly work?

A Word document is NOT a plain text file.  All the control characters embedded in the document that tell MSWord how to format that document would prevent it from being displayed properly.  The only way your code would work was if "file.doc" was actually a ".txt" file that has been renamed to a ".doc" file...
0
 
bman9111Commented:
I use dsoframer....this embeds word or any other office application to my vb.net or c# form...
Pretty nice


http://support.microsoft.com/default.aspx?scid=kb;en-us;311765
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now