Re: Add Certain Words Within Document to Index

Hello.
Thanks for your request. I think you can use ReplaceEvaluator in this case. Please follow this link to learn how to use ReplaceEvaluator
https://reference.aspose.com/words/net/aspose.words/range/replace/
Also here is a simple example which shows how to find text and insert XE fields.

// Open document.
Document doc = new Document(@"Test007\in.doc");
// Insert XE fields at text "word"
doc.Range.Replace(new Regex(@"word"), new ReplaceEvaluator(InserXEEvaluator), false);
// Save document.
doc.Save(@"Test007\out.doc");
private static ReplaceAction InserXEEvaluator(object sender, ReplaceEvaluatorArgs e)
{
    DocumentBuilder builder = new DocumentBuilder((Document) e.MatchNode.Document);
    builder.MoveTo(e.MatchNode);
    // Insert XE field
    builder.InsertField("XE \"word\"", null);
    return ReplaceAction.Skip;
}

Hope this helps.

Hello.
Thanks for your request. I think you can use ReplaceEvaluator in this case. Please follow this link to learn how to use ReplaceEvaluator
https://reference.aspose.com/words/net/aspose.words/range/replace/
Also here is a simple example which shows how to find text and insert XE fields.

// Open document.
Document doc = new Document(@"Test007\in.doc");
// Insert XE fields at text "word"
doc.Range.Replace(new Regex(@"word"), new ReplaceEvaluator(InserXEEvaluator), false);
// Save document.
doc.Save(@"Test007\out.doc");
private static ReplaceAction InserXEEvaluator(object sender, ReplaceEvaluatorArgs e)
{
    DocumentBuilder builder = new DocumentBuilder((Document) e.MatchNode.Document);
    builder.MoveTo(e.MatchNode);
    // Insert XE field
    builder.InsertField("XE \"word\"", null);
    return ReplaceAction.Skip;
}

Hope this helps.