RemoveUnusedFields

Hello, would need a small example of using RemoveUnusedFields.

Hi
György,

Thanks for your inquiry. This code tells, how you can remove empty paragraphs where you can observe “How field removed from document”.

Document doc = new Document("d:/test.docx");
NodeList fields = doc.SelectNodes("//FieldStart");
foreach(FieldStart field in fields)
{
    if (field.FieldType == FieldType.FieldMergeField)
        if (field.ParentNode != null)
            field.ParentNode.Remove();
}

Follow up for further detail:
https://reference.aspose.com/words/net/aspose.words.fields/field/remove/

In case of any ambiguity, please share your scenario.

Thank you very much.

Hi György,
Thank you very much for your feedback. It is great to hear that your issue has been resolved. You are always welcome and please feel free to ask if you have any query in future.

We always welcome constructive response from our customers.

Hi there,

Thanks for your inquiry.

I’m afraid Imran is providing an old work around for what you are looking for . I suppose you wish to know about MailMergeCleanupOptions.RemoveUnusedFields. Please see the code below which demonstrates how to use this. Enabling this flag will automatically remove any merge fields in the document which are not merged with any data.

doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
doc.MailMerge.Execute(myData);

If we can help with anything else, please feel free to ask.

Thanks,

Right, that was the actual question
Thank you very much