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

Free Support Forum - aspose.com

To Read Cross Reference Properties using aspose.word .net C#

Hi,
My requirement is to read properties of cross reference show in below picture of word document through coding c#.

In those properties I need to find cross references that are created by Only Label And Number property only
Already tried below code but unable to find those properties

foreach (Field field in doc.Range.Fields)
{
    if (field.Type.Equals(FieldType.FieldRef))
    {
        FieldRef fieldRef = (FieldRef)field;
        Console.WriteLine(doc.Range.Bookmarks[fieldRef.DisplayResult].Text);
    }
}

Please Help Me,

@Nagasrinu Cross reference inserted with Only Label And Number selected is inserted like this:
{ REF _Ref123821616 \h }

There is no additional switches set except \h (Creates a hyperlink to the bookmarked paragraph.). So you can consider such REF field without additional switches as the one created with Only Label And Number option selected.

If you would like to get text of the REF field’s bookmark, you can use code like this:

FieldRef fieldRef = (FieldRef)field;
Console.WriteLine(doc.Range.Bookmarks[fieldRef.BookmarkName].Text);

fieldRef.DisplayResult returns the value displayed by the REF field.

1 Like

Hi,
Thank you for fast Response. But, I need to find different types of cross references based upon condition. So, I need to differentiate those types[Entire Caption, Only Label And number, Only Caption Text, Page Number, Above/Below] among themselves. Is There any Property or Procedure to identify those properties uniquely.
Please help me.

@Nagasrinu Unfortunately, there is no way to determine what option has been used to insert REF field by analyzing REF field, except Page Number options, because in this case PAGEREF field is used. For example see the following screenshot:

As you can see cross references inserted with Entire Caption and Only Label And number look exactly the same.
The cross references inserted with Only Caption Text refers to different bookmark that wraps "after" text only.
The cross references inserted with Page Number is inserted as PAGEREF field.
The cross references inserted with Above/Below has \p switch set. This switch corresponds to FieldRef.InsertRelativePosition property in Aspose.Words API.