Read conditional block

I am trying to read Conditional Blocks (IF ELSE Fields) in 1200+ documents

I’d like to log if the document contains Conditional Blocks, and what the condition is.

I use this code to get normal mergefields, but I cannot get the conditinal blocks

foreach (var fld in doc.Range.FormFields)
{
   string type = fld.Type switch
   {
       Aspose.Words.Fields.FieldType.FieldFormDropDown => "wdFieldFormDropDown",
       Aspose.Words.Fields.FieldType.FieldFormCheckBox => "wdFieldFormCheckBox",
       Aspose.Words.Fields.FieldType.FieldFormTextInput => "wdFieldFormTextInput",
       _ => Enum.GetName(typeof(Aspose.Words.Fields.FieldType), fld.Type.GetTypeCode())
   };
...

Thanks in advance


This Topic is created by tilal.ahmad using Email to Topic tool.

@it-mailboks You can use Document.Range.Fields to iterate over the fields in the document. Please see the following code:

Document doc = new Document(@"C:\Temp\in.docx");
foreach (Field f in doc.Range.Fields)
{
    if (f.Start.FieldType == FieldType.FieldIf)
        Console.WriteLine(f.GetFieldCode());
}