Read Word file

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

How can I read a word file from C#?
I need to process each word of the document for a work.

Thank you.
 
Do you mean a MS Word document or a text document. If you want to read a
text document the following is the snippet, you could

string path = @"c:\temp\temp.txt";

// This text is added only once to the file.
if (!File.Exists(path))
throw new FileNotFoundException("File not found");

// Open the file to read from to read line by line and storing it
in an array.
string[] readText = File.ReadAllLines(path);
foreach (string s in readText)
Console.WriteLine(s);

// Open the file to read from to read the entire contents into a
string
string text = File.ReadAllText(path);
Console.WriteLine(text);


-Arun
 
I mean a Word document.
Thank you
Arunkumar Keserla said:
Do you mean a MS Word document or a text document. If you want to read a
text document the following is the snippet, you could
string path = @"c:\temp\temp.txt";

// This text is added only once to the file.
if (!File.Exists(path))
throw new FileNotFoundException("File not found");

// Open the file to read from to read line by line and storing it
in an array.
string[] readText = File.ReadAllLines(path);
foreach (string s in readText)
Console.WriteLine(s);

// Open the file to read from to read the entire contents into a
string
string text = File.ReadAllText(path);
Console.WriteLine(text);


-Arun

How can I read a word file from C#?
I need to process each word of the document for a work.
Thank you.
 

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

Back
Top