title: is there a way to read a word document line by line
body: <p>I am trying to extract all the words in a Word document. I am able to do it all in one go as follows...</p>
  
  <pre><code>Word.Application word = new Word.Application();
  doc = word.Documents.Open(@"C:\SampleText.doc");
  doc.Activate();
  
  foreach (Word.Range docRange in doc.Words) // loads all words in document
  {
      IEnumerable&lt;string&gt; sortedSubstrings = Enumerable.Range(0, docRange.Text.Trim().Length)
          .Select(i =&gt; docRange.Text.Substring(i))
          .OrderBy(s =&gt; s.Length &lt; 3 ? s : s.Remove(2, Math.Min(s.Length - 2, 2)));
  
      wordPosition =
          (int)
          docRange.get_Information(
              Microsoft.Office.Interop.Word.WdInformation.wdFirstCharacterColumnNumber);
  
      foreach (var substring in sortedSubstrings)
      {
          index = docRange.Text.IndexOf(substring) + wordPosition;
          charLocation[index] = substring;
      }
  }
  </code></pre>
  
  <p>However I would have preferred to load the document one line at a time... is it possible to do so?</p>
  
  <p>I can load it by paragraph however I am unable to iterate through the paragraphs to extract all words.</p>
  
  <pre><code>foreach (Word.Paragraph para in doc.Paragraphs)
  {
      foreach (Word.Range docRange in para) // Error: type Word.para is not enumeranle**
      {
          IEnumerable&lt;string&gt; sortedSubstrings = Enumerable.Range(0, docRange.Text.Trim().Length)
              .Select(i =&gt; docRange.Text.Substring(i))
              .OrderBy(s =&gt; s.Length &lt; 3 ? s : s.Remove(2, Math.Min(s.Length - 2, 2)));
  
          wordPosition =
              (int)
              docRange.get_Information(
                  Microsoft.Office.Interop.Word.WdInformation.wdFirstCharacterColumnNumber);
  
          foreach (var substring in sortedSubstrings)
          {
              index = docRange.Text.IndexOf(substring) + wordPosition;
              charLocation[index] = substring;
          }
  
      }
  }
  </code></pre>