Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:07:27+00:00 2026-05-31T06:07:27+00:00

I have a chunk of code that I’m using to read MS Office Word

  • 0

I have a chunk of code that I’m using to read MS Office Word documents.

static void ReadMSOfficeWordFile(string file) {
    try {
        Microsoft.Office.Interop.Word.Application msWordApp = new Microsoft.Office.Interop.Word.Application();
        object nullobj = System.Reflection.Missing.Value;
        object ofalse = false;
        object ofile = file;

        Microsoft.Office.Interop.Word.Document doc = msWordApp.Documents.Open(
                                                    ref ofile, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj, ref nullobj, ref nullobj,
                                                    ref nullobj);
        string result = doc.Content.Text.Trim();
        doc.Close(ref ofalse, ref nullobj, ref nullobj);
        msWordApp.Quit();
        CheckLineMatch(file, result);
    }
    catch {
        RaiseError("Unable to parse file because of MS Office error.", file);
    }
}

I have three issues with this.

First- It relies on MS Office being installed on each system this might run on. Some people prefer Libre Office, but this still needs to run against MS Office Word documents.

Second- I don’t know if this will even work for MS Office 2003 AND MS Office 2007 documents…

Third- It’s SLOW. It’s excruciatingly slow.

SO! I assume there MUST be a better way to run it than this. I’m guessing that someone has to know of a better way than what a novice is coming with. I’m only trying to read the text in the document, nothing else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:07:28+00:00Added an answer on May 31, 2026 at 6:07 am

    In response to your “Word application hanging open”, you need to tell it to close.

    msWordApp.Quit()
    

    See http://msdn.microsoft.com/en-us/library/bb215475(v=office.12).aspx

    Regarding the “relies on MS Offise being installed”, you are using the interop. So by definition is requires it to be installed. You can look into one of the commercial libraries.

    http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
    http://www.gemboxsoftware.com/document/pricelist

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a chunk of code that I'm using to get the UNC path
I have a chunk of code where it appears that a variable is changing
I have a rather large chunk of code that breaks sometimes, as far as
I have a chunk of code that defines div s and some of the
All, I have a chunk of code that runs over a lot of records
I have written a chunk of code that is aimed at reordering pages. <form
I have a fairly large chunk of code that produces/returns an arraylist of search
Another migration question, I have another chunk of VB6 code that seems to need
I have a the following chunk of code that's adding up to six Player
I have a large chunk of legacy php code that I need to interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.