Find the specific text in paragraph and copy that paragraph to other document in Aspose.Words c#

Find the specific text in paragraph and copy that paragraph to other document in Aspose.Words c#.

@Yuvarajshivananjappa Sure, you can use IReplacingCallback to get paragraph with matched text. And then use Document.ImportNode method to import paragraph to the target document. For example see the following code that copies paragraph with matched text into the target document:

Document doc = new Document(@"C:\Temp\in.docx");
Document targetDocument = new Document();

FindReplaceOptions options = new FindReplaceOptions();
options.ReplacingCallback = new CopyParagraphCallback(targetDocument);
doc.Range.Replace("Copy me", "", options);

targetDocument.Save(@"C:\Temp\out.docx");
private class CopyParagraphCallback : IReplacingCallback
{
    public CopyParagraphCallback(Document targetDoc)
    {
        mTargetDocument = targetDoc;
    }

    public ReplaceAction Replacing(ReplacingArgs args)
    {
        // Get the matched paragraph.
        Paragraph para = args.MatchNode.NodeType == NodeType.Paragraph 
            ? (Paragraph)args.MatchNode 
            : (Paragraph)args.MatchNode.GetAncestor(NodeType.Paragraph);

        // Import the paragraph.
        Node targetPara = mTargetDocument.ImportNode(para, true, ImportFormatMode.KeepSourceFormatting);

        // Insert the paragraph into the target document.
        mTargetDocument.FirstSection.Body.AppendChild(targetPara);

        return ReplaceAction.Skip;
    }

    private Document mTargetDocument;
}