Unlinking a field that contains other links is not working properly

I have a document that has an INCLUDETEXT field to document that has other fields in it (could be other INCLUDETEXT or MERGEFIELD…) when I run the UnlinkFields code below I get a very strange result, in that the first field contained within the document being INCLUDETEXT has the text attached to it instead of just being a field followed by text.

How do I handle unliking a field that contans other fields?

Thanks,

private static void UnlinkFields(CompositeNode compositeNode, Aspose.Words.Fields.FieldType targetFieldType)
{
    ArrayList fieldStarts = new ArrayList();
    NodeCollection starts = compositeNode.GetChildNodes(NodeType.FieldStart, true);

    foreach (FieldStart start in starts)
    {
        if (start.FieldType == targetFieldType)
        {
            fieldStarts.Add(start);
        }
    }

    foreach (FieldStart start in fieldStarts)
    {
        Node currentNode = start;
        Node fieldSeparator = null;

        while (currentNode.NodeType != NodeType.FieldSeparator && currentNode.NodeType != NodeType.FieldEnd)
        {
            currentNode = currentNode.NextSibling;
            currentNode.PreviousSibling.Remove();
        }

        if (currentNode.NodeType == NodeType.FieldSeparator)
        {
            fieldSeparator = currentNode;
            while (currentNode.NodeType != NodeType.FieldEnd)
            {
                currentNode = currentNode.NextPreOrder(compositeNode.Document);
            }
            fieldSeparator.Remove();
        }

        currentNode.Remove();
    }
}

Hi Darel,
Thanks for your inquiry.
Currently this article is a draft as stated near the top. The code itself is a simple implementation that acts as a place holder until the new Field API is released (which will support this fully through a one line API call). The current implementation has a few restrictions right now as it won’t work with nested fields or fields whose FieldCode or FieldResult span over mulitple paragraphs.
In the mean time you could implement the code from this thread which appears to have some support for converting nested fields to static text.
Thanks,

Thanks, do you have an ETA on the Field API?
One other alternative would be for me to replace the INCLUDETEXT with the actual document, is there a way to delete the INCLUDETEXT field entirely (including all it’s text, and the embedded fields)?

Hi Darel,
Thanks for your inquiry.
I’m afraid there is no set date for these new API additions yet. It should be sometime in the next 1-2 months. We will keep you informed of any developments.
Sure, you can remove the IncludeText field from the document. Since your fields are nested you may want to try using this code here.
If you have any problems please feel free to ask for some help.
Thanks,

Adam,
Any word on when the API will done?
Thanks,
Darel

Hello Darel,
Thanks for your request. Unfortunately, the issue is still unresolved. At the moment this issue is pending for analysis. The responsible developer will analyze the issue and we will be able to provide you an estimate.
Best regards,

The issues you have found earlier (filed as WORDSNET-976) have been fixed in this Aspose.Words for .NET 16.10.0 update and this Aspose.Words for Java 16.10.0 update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(4)