Reading a word document into a string c#

T

Tim McOwan

Hi All,

Don't know if this is the right newsgroup but I need the ability to read the
contents of a word document into a string using C# (but any .NET examples
would be great)

Please help.

Thanks,
 
C

Cindy M -WordMVP-

Hi Tim,
Don't know if this is the right newsgroup but I need the ability to read the
contents of a word document into a string using C# (but any .NET examples
would be great)
Well, taken absolutely literally, that would go something like this (off the
top of my head, so syntax errors are possible!)

word.document doc = wdapp.ActiveDocument;
string s = doc.Content.Text

this will capture all TEXT in the body of the document - not headers, footers,
footnotes, anything in text boxes, etc. If you need that, then you also need to
loop through the StoryRanges. For more on that, including sample (VBA) code,
look up StoryRange, StoryRanges and all related topics in the object model
Help.

Note that this is most decidedly NOT the best place to ask, as this group is
aimed at end-users :) One of the office.developer newsgroups would be more
appropriate or, at a pinch a word.vba group.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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