Greetings –
I’m having a bit of trouble will RemoveEmptyParagraphs + DeleteFields(). I’ve seen other posts on this topic and saw a message from Dimitry in which he suggested that in addition to that property and method, you should add the following code:
NodeList fields = doc.SelectNodes("//FieldStart");
foreach (FieldStart field in fields)
{
if (field.FieldType == FieldType.FieldMergeField)
field.ParentNode.Remove();
}
That works most of the time, however, occasionally I'll get an error while going through this loop that says essentially "Cannot remove because there is no parent".
Can you describe why a field would not have a ParentNode? Would the loop be improved if I checked for a ParentNode? Maybe this:
NodeList fields = doc.SelectNodes("//FieldStart");
foreach (FieldStart field in fields)
{
if (field.FieldType == FieldType.FieldMergeField &&
field.ParentNode != null )
field.ParentNode.Remove();
}