We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com


Hello, would need a small example of using RemoveUnusedFields.


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)



Follow up for further detail:

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.

<span style=“font-size:
10.0pt;font-family:“Courier New”;mso-no-proof:yes”>doc.MailMerge.CleanupOptions
= MailMergeCleanupOptions.RemoveUnusedFields;<o:p></o:p>


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


Right, that was the actual question :slight_smile:
Thank you very much