Need to find whether the autotext is in Header or Body or Footer - .Net - Aspose words

Hi, Can you pls help me to find whether the autotext in word document is placed in Header or Body or Footer?

Document doc = new Document("C:\\temp\\SampleSourceFile\\SampleDoc.dot");

foreach (Field field in doc.Range.Fields)
{
    if (field.Type.Equals(FieldType.FieldAutoText))
    {
        if (((Aspose.Words.Fields.FieldAutoText)field).EntryName == "CusName") //How to check whether the cusName autotext is in Header or Body or Footer?
        {
            DocumentBuilder builder = new DocumentBuilder(doc);

            if (field.Result.Equals("Error! AutoText entry not defined.")) 
            {
              
            }
        }
    }
}

@NanthiniSenthil123,

You can use the following C# code of Aspose.Words for .NET API to determine if an AutoText field in Word document is inside Header, Footer or Body story:

Document doc = new Document("C:\\temp\\SampleSourceFile\\SampleDoc.dot");

foreach (Field field in doc.Range.Fields)
{
    if (field.Type.Equals(FieldType.FieldAutoText))
    {
        if (((Aspose.Words.Fields.FieldAutoText)field).EntryName == "CusName") //How to check whether the cusName autotext is in Header or Body or Footer?
        {
            DocumentBuilder builder = new DocumentBuilder(doc);

            if (field.Result.Equals("Error! AutoText entry not defined."))
            {
                // check if it is in Header Footer story
                HeaderFooter headerFooter = (HeaderFooter)field.Start.GetAncestor(NodeType.HeaderFooter);
                if (headerFooter != null)
                {
                    Console.WriteLine("It is in " + headerFooter.HeaderFooterType);
                }
                else
                {
                    // check if it is in Body story
                    Body body = (Body)field.Start.GetAncestor(NodeType.Body);
                    if (body != null)
                    {
                        Console.WriteLine("It is in Body");
                    }
                }
            }
        }
    }
}