How do I display a file

Posted on 2006-04-26
Last Modified: 2010-04-23
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.

Question by:vlvawter
    LVL 5

    Expert Comment


    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
    '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
    ----EXAMPLE CODE----
    LVL 85

    Expert Comment

    by:Mike Tomlinson 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...
    LVL 8

    Accepted Solution

    I use dsoframer....this embeds word or any other office application to my or c# form...
    Pretty nice;en-us;311765

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now