Hi babu935,
Pease refer the beow code.
Namespace
You need to import the beow name space.
using Word = Microsoft.Office.Interop.Word;
Code
protected void btnGet_Click(object sender, EventArgs e)
{
object fileName = ""; //The filepath goes here
string textToFind = ""; //The text to find goes here
Word.Application word = new Word.Application();
Word.Document doc = new Word.Document();
object missing = System.Type.Missing;
try
{
doc = word.Documents.Open(ref fileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
doc.Activate();
foreach (Word.Range docRange in doc.Words)
{
if (docRange.Text.Trim().Equals(textToFind,
StringComparison.CurrentCultureIgnoreCase))
{
docRange.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow;
docRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdWhite;
}
Response.Write(docRange.Text);
}
}
catch (Exception ex)
{
Response.Write("Error : " + ex.Message);
}
}