Finding All form fields and Fill in (Merge fields) in Word Doc

Hi,
I have a document. It contains Form fields(Text Box, Check box, etc) and Fill in fields. I have to find out what are all the fields avialable in the doc.
Thanking you.
Soloman

This message was posted using Page2Forum from Technical Support - Aspose.Words for .NET and Java

Hello!
Thank you for your inquiry.
You can select all the nodes of particular type using XPath expressions:

private static void FindAllFormFields()
{
    // Load the document
    Document doc = new Document("source.doc");
    // Select all nodes of type FormField in this document
    NodeList formFields = doc.SelectNodes("//FormField");
    // Traverse the list
    foreach(FormField ff in formFields)
    {
        // Do something with them all...
        // ...
    }
    doc.Save("result.doc");
}

Here are only form fields in the sample. What objects do you mean under fill-in fields?
Regards,

Hi,
Thanks for your reply. Fill- in Fields comes under insert menu/Field.
In categories select mail Merge. In Field Names fill-in field is available.It is like Fill in blanks.
If we place this field in a form how can we loop thro all these fields?
Your help is greatly appreciated.
Regards,
Soloman
solomon_philip@yahoo.com

Hello!
Thank you for explanation. I should kill my brake…
You can find and manipulate with Fill-In fields this way:

private static void FindSomeFields()
{
    // Load the document
    Document doc = new Document("source.doc");
    // Select all nodes of type FormField in this document
    NodeList fieldStarts = doc.SelectNodes("//FieldStart");
    // Traverse the list
    foreach(FieldStart start in fieldStarts)
    {
        if (start.FieldType == FieldType.FieldFillIn)
        {
            // We found the start node of a Fill-In field.
            // Do something...
            // ...
        }
    }
    doc.Save("result.doc");
}

If you are just collecting their names then that’s enough.
Have a nice day,