FieldSeq Class
Implements the SEQ field.
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsField
    Aspose.Words.FieldsFieldSeq

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public class FieldSeq : Field

The FieldSeq type exposes the following members.

Constructors
  NameDescription
Public methodFieldSeq
Initializes a new instance of the FieldSeq class
Properties
  NameDescription
Public propertyCode exampleBookmarkName
Gets or sets a bookmark name that refers to an item elsewhere in the document rather than in the current location.
Public propertyCode exampleDisplayResult
Gets the text that represents the displayed field result.
(Inherited from Field.)
Public propertyCode exampleEnd
Gets the node that represents the field end.
(Inherited from Field.)
Public propertyCode exampleFormat
Gets a FieldFormat object that provides typed access to field's formatting.
(Inherited from Field.)
Public propertyCode exampleInsertNextNumber
Gets or sets whether to insert the next sequence number for the specified item.
Public propertyCode exampleIsDirty
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field.)
Public propertyCode exampleIsLocked
Gets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field.)
Public propertyCode exampleLocaleId
Gets or sets the LCID of the field.
(Inherited from Field.)
Public propertyCode exampleResetHeadingLevel
Gets or sets an integer number representing a heading level to reset the sequence number to. Returns -1 if the number is absent.
Public propertyCode exampleResetNumber
Gets or sets an integer number to reset the sequence number to. Returns -1 if the number is absent.
Public propertyCode exampleResult
Gets or sets text that is between the field separator and field end.
(Inherited from Field.)
Public propertyCode exampleSeparator
Gets the node that represents the field separator. Can be null.
(Inherited from Field.)
Public propertyCode exampleSequenceIdentifier
Gets or sets the name assigned to the series of items that are to be numbered.
Public propertyCode exampleStart
Gets the node that represents the start of the field.
(Inherited from Field.)
Public propertyCode exampleType
Gets the Microsoft Word field type.
(Inherited from Field.)
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodCode exampleGetFieldCode
Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
(Inherited from Field.)
Public methodCode exampleGetFieldCode(Boolean)
Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodNeedStoreOldResultNodes (Inherited from Field.)
Public methodCode exampleRemove
Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null.
(Inherited from Field.)
Public methodToString (Inherited from Object.)
Public methodCode exampleUnlink
Performs the field unlink.
(Inherited from Field.)
Public methodCode exampleUpdate
Performs the field update. Throws if the field is being updated already.
(Inherited from Field.)
Public methodCode exampleUpdate(Boolean)
Performs a field update. Throws if the field is being updated already.
(Inherited from Field.)
Remarks
Sequentially numbers chapters, tables, figures, and other user-defined lists of items in a document.
Examples
Insert a TOC field and build the table with SEQ fields.
public void TocSeqPrefix()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Filter by sequence identifier and a prefix sequence identifier, and change sequence separator
    FieldToc fieldToc = (FieldToc)builder.InsertField(FieldType.FieldTOC, true);
    fieldToc.TableOfFiguresLabel = "MySequence";
    fieldToc.PrefixedSequenceIdentifier = "PrefixSequence";
    fieldToc.SequenceSeparator = ">";

    Assert.AreEqual(" TOC  \\c MySequence \\s PrefixSequence \\d >", fieldToc.GetFieldCode());

    builder.InsertBreak(BreakType.PageBreak);

    // Add two SEQ fields in one paragraph, setting the TOC's sequence and prefix sequence as their sequence identifiers
    FieldSeq fieldSeq = InsertSeqField(builder, "PrefixSequence ", "", "PrefixSequence");
    Assert.AreEqual(" SEQ  PrefixSequence", fieldSeq.GetFieldCode());

    fieldSeq = InsertSeqField(builder, ", MySequence ", "\n", "MySequence");
    Assert.AreEqual(" SEQ  MySequence", fieldSeq.GetFieldCode());

    InsertSeqField(builder, "PrefixSequence ", "", "PrefixSequence");
    InsertSeqField(builder, ", MySequence ", "\n", "MySequence");

    // If the sqeuence identifier doesn't match that of the TOC, the entry won't be included
    InsertSeqField(builder, "PrefixSequence ", "", "PrefixSequence");           
    fieldSeq = InsertSeqField(builder, ", MySequence ", "", "OtherSequence");
    builder.Writeln(" This text, from a different sequence, won't be included in the same TOC as the one above.");

    Assert.AreEqual(" SEQ  OtherSequence", fieldSeq.GetFieldCode());

    doc.UpdateFields();
    doc.Save(ArtifactsDir + "Field.TOC.SEQ.Prefix.docx");
}

[Ignore("WORDSNET-18083")]
public void TocSeqNumbering()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Filter by sequence identifier and a prefix sequence identifier, and change sequence separator
    FieldToc fieldToc = (FieldToc)builder.InsertField(FieldType.FieldTOC, true);
    fieldToc.TableOfFiguresLabel = "MySequence";

    Assert.AreEqual(" TOC  \\c MySequence", fieldToc.GetFieldCode());

    builder.InsertBreak(BreakType.PageBreak);

    // Set the current number of the sequence to 100
    FieldSeq fieldSeq = InsertSeqField(builder, "MySequence ", "\n", "MySequence");
    fieldSeq.ResetNumber = "100";
    Assert.AreEqual(" SEQ  MySequence \\r 100", fieldSeq.GetFieldCode());

    fieldSeq = InsertSeqField(builder, "MySequence ", "\n", "MySequence");

    // Insert a heading
    builder.InsertBreak(BreakType.ParagraphBreak);
    builder.ParagraphFormat.Style = doc.Styles["Heading 1"];
    builder.Writeln("My heading");
    builder.ParagraphFormat.Style = doc.Styles["Normal"];

    // Reset sequence when we encounter a heading, resetting the sequence back to 1
    fieldSeq = InsertSeqField(builder, "MySequence ", "\n", "MySequence");
    fieldSeq.ResetHeadingLevel = "1";
    Assert.AreEqual(" SEQ  MySequence \\s 1", fieldSeq.GetFieldCode());

    // Move to the next number
    fieldSeq = InsertSeqField(builder, "MySequence ", "\n", "MySequence");
    fieldSeq.InsertNextNumber = true;
    Assert.AreEqual(" SEQ  MySequence \\n", fieldSeq.GetFieldCode());

    doc.UpdateFields();
    doc.Save(ArtifactsDir + "Field.TOC.SEQ.ResetNumbering.docx");
}

[Ignore("WORDSNET-18084")]
public void TocSeqBookmark()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // This TOC takes in all SEQ fields with "MySequence" inside "TOCBookmark"
    FieldToc fieldToc = (FieldToc)builder.InsertField(FieldType.FieldTOC, true);
    fieldToc.TableOfFiguresLabel = "MySequence";
    fieldToc.BookmarkName = "TOCBookmark";
    builder.InsertBreak(BreakType.PageBreak);

    Assert.AreEqual(" TOC  \\c MySequence \\b TOCBookmark", fieldToc.GetFieldCode());

    InsertSeqField(builder, "MySequence ", "", "MySequence");
    builder.Writeln(" This text won't show up in the TOC because it is outside of the bookmark.");

    builder.StartBookmark("TOCBookmark");

    InsertSeqField(builder, "MySequence ", "", "MySequence");
    builder.Writeln(" This text will show up in the TOC next to the entry for the above caption.");

    InsertSeqField(builder, "OtherSequence ", "", "OtherSequence");
    builder.Writeln(" This text, from a different sequence, won't be included in the same TOC as the one above.");

    // The contents of the bookmark we reference here will not appear at the SEQ field, but will appear in the corresponding TOC entry
    FieldSeq fieldSeq = InsertSeqField(builder, " MySequence ", "\n", "MySequence");
    fieldSeq.BookmarkName = "SEQBookmark";
    Assert.AreEqual(" SEQ  MySequence SEQBookmark", fieldSeq.GetFieldCode());

    // Add bookmark to reference
    builder.InsertBreak(BreakType.PageBreak);
    builder.StartBookmark("SEQBookmark");
    InsertSeqField(builder, " MySequence ", "", "MySequence");
    builder.Writeln(" Text inside SEQBookmark.");
    builder.EndBookmark("SEQBookmark");

    builder.EndBookmark("TOCBookmark");

    doc.UpdateFields();
    doc.Save(ArtifactsDir + "Field.TOC.SEQ.Bookmark.docx");
}

/// <summary>
/// Insert a sequence field with preceding text and a specified sequence identifier
/// </summary>
public FieldSeq InsertSeqField(DocumentBuilder builder, string textBefore, string textAfter, string sequenceIdentifier)
{
    builder.Write(textBefore);
    FieldSeq fieldSeq = (FieldSeq)builder.InsertField(FieldType.FieldSequence, true);
    fieldSeq.SequenceIdentifier = sequenceIdentifier;
    builder.Write(textAfter);

    return fieldSeq;
}
See Also