title: searching a word document in c#
body: <p>I am making a search module(windows form in C#). Its working fine for .txt files but
  I need to search for the word in the Word document too.
  i tried using Microsoft.Office.Interop.Word;
  and the code was as below</p>
  
  <pre><code>Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
  Microsoft.Office.Interop.Word.Document docOpen = app.Documents.Open(flname);
  StreamReader srObj = new StreamReader(flname);
  string read = srObj.ReadToEnd();
  if (read.Contains(txtWordInput.Text)) // searching for the input word in the file
  {
        count1++;
        lbSearchList.Visible = true;
        lbSearchList.Items.Add(flname);
  }
  srObj.Close();
  app.Documents.Close();
  </code></pre>
  
  <p>but it at run time it gave an error that the doc file is already open hence is not accessible even when the document wasn't open.</p>
  
  <p>then i tried working simply with stream reader, it worked and did read the file but the data read was some random symbols and not what was actually written inside. Due to this  the
       if (read.Contains(txtWordInput.Text))  statement was unable to search for the word.</p>
  
  <p>please help me with the code as to how to successfully search for the word in the word document.</p>