public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_FindAndReplace();
string fileName = "Field.ReplaceTextWithFields.doc";
Document doc = new Document(dataDir + fileName);
FindReplaceOptions options = new FindReplaceOptions();
options.ReplacingCallback = new ReplaceTextWithFieldHandler(FieldType.FieldMergeField);
// Replace any "PlaceHolderX" instances in the document (where X is a number) with a merge field.
doc.Range.Replace(new Regex(@"PlaceHolder(\d+)"), "", options);
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
doc.Save(dataDir);
Console.WriteLine("\nText replaced with field successfully.\nFile saved at " + dataDir);
}
}