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

Free Support Forum - aspose.com

Get the first Field or Table object below the specified starting point

Here is a VSTO function that I’m trying to translate to Aspose.Words:

public Field GetNextField(Range rng, int selStart)
{
    var NextField = (from f in rng.Fields
                        where f.Start > selStart
                        orderby f.Code.Start
                        select f).FirstOrDefault();

    return NextField;
}

It is a bit of LINQ, but the basic idea is to get the first Field object that appears after the specified selStart. In VSTO, I could do this simply by comparing Field.Start to selStart, but in Aspose.Words, Field object’s Start property doesn’t seem to provide its starting/ending positions.

What would be my workaround?

@Shujee Field.Start property returns FieldStart node of the corresponding field. Fields in Aspose.Words DOM is represented like the following:


Please see the documentation to learn more about working with fields.

There is no integer property that specifies position of a particular node in the Range. In your case you can use either Node.NextSibling property or Node.NextPreOrder method to get nodes that follows the specified one. But, could you please describe the ultimate goal? I am sure we will find a way to achieve what is required.

Our current application design requires position information of the Field objects, like VSTO provides. I have given it some more thought and I think I can live without integer position by moving away from the Iterator pattern we’re currently using. I’ll get back if that doesn’t work for us.

@Shujee Sure, please, feel free to ask in case of any issues.
I think in your case you can consider using DocumentVisitor approach to step through the document tree.