ReplacingArgsMatchNode Property |
Namespace: Aspose.Words.Replacing
public void InsertDocumentAtReplace() { Document mainDoc = new Document(MyDir + "Document insertion destination.docx"); FindReplaceOptions options = new FindReplaceOptions(); options.Direction = FindReplaceDirection.Backward; options.ReplacingCallback = new InsertDocumentAtReplaceHandler(); mainDoc.Range.Replace(new Regex("\\[MY_DOCUMENT\\]"), "", options); mainDoc.Save(ArtifactsDir + "InsertDocument.InsertDocumentAtReplace.doc"); } private class InsertDocumentAtReplaceHandler : IReplacingCallback { ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) { Document subDoc = new Document(MyDir + "Document.docx"); // Insert a document after the paragraph, containing the match text Paragraph para = (Paragraph) args.MatchNode.ParentNode; InsertDocument(para, subDoc); // Remove the paragraph with the match text para.Remove(); return ReplaceAction.Skip; } }