EditableRangeStart Class

Represents a start of an editable range in a Word document.
Inheritance Hierarchy

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public sealed class EditableRangeStart : Node

The EditableRangeStart type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleDocument
Gets the document to which this node belongs.
(Inherited from Node.)
Public propertyCode exampleEditableRange
Gets the facade object that encapsulates this editable range start and end.
Public propertyCode exampleId
Specifies the identifier of the editable range.
Public propertyCode exampleIsComposite
Returns true if this node can contain other nodes.
(Inherited from Node.)
Public propertyCode exampleNextSibling
Gets the node immediately following this node.
(Inherited from Node.)
Public propertyCode exampleNodeType (Overrides NodeNodeType.)
Public propertyCode exampleParentNode
Gets the immediate parent of this node.
(Inherited from Node.)
Public propertyCode examplePreviousSibling
Gets the node immediately preceding this node.
(Inherited from Node.)
Public propertyCode exampleRange
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.)
Methods
  NameDescription
Public methodCode exampleAccept
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).)
Public methodCode exampleClone (Inherited from Node.)
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetAncestor(Type)
Gets the first ancestor of the specified object type.
(Inherited from Node.)
Public methodCode exampleGetAncestor(NodeType)
Gets the first ancestor of the specified NodeType.
(Inherited from Node.)
Public methodGetHashCode (Inherited from Object.)
Public methodCode exampleGetText
Gets the text of this node and of all its children.
(Inherited from Node.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleNextPreOrder
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode examplePreviousPreOrder
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.)
Public methodCode exampleRemove
Removes itself from the parent.
(Inherited from Node.)
Public methodToString (Inherited from Object.)
Public methodCode exampleToString(SaveFormat)
Exports the content of the node into a string in the specified format.
(Inherited from Node.)
Public methodCode exampleToString(SaveOptions)
Exports the content of the node into a string using the specified save options.
(Inherited from Node.)
Remarks

A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id.

EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.

Use the EditableRange class as a "facade" to work with an editable range as a single object.

Note Note
Currently editable ranges are supported only at the inline-level, that is inside Paragraph, but editable range start and editable range end can be in different paragraphs.
Examples
Shows how to start and end an editable range.
public void CreateEditableRanges()
{
    Document doc = new Document(MyDir + "Document.docx");
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Start an editable range
    EditableRangeStart edRange1Start = builder.StartEditableRange();

    // An EditableRange object is created for the EditableRangeStart that we just made
    EditableRange editableRange1 = edRange1Start.EditableRange;

    // Put something inside the editable range
    builder.Writeln("Paragraph inside first editable range");

    // An editable range is well-formed if it has a start and an end
    // Multiple editable ranges can be nested and overlapping 
    EditableRangeEnd edRange1End = builder.EndEditableRange();

    // Explicitly state which EditableRangeStart a new EditableRangeEnd should be paired with
    EditableRangeStart edRange2Start = builder.StartEditableRange();
    builder.Writeln("Paragraph inside second editable range");
    EditableRange editableRange2 = edRange2Start.EditableRange;
    EditableRangeEnd edRange2End = builder.EndEditableRange(edRange2Start);

    // Editable range starts and ends have their own respective node types
    Assert.AreEqual(NodeType.EditableRangeStart, edRange1Start.NodeType);
    Assert.AreEqual(NodeType.EditableRangeEnd, edRange1End.NodeType);

    // Editable range IDs are unique and set automatically
    Assert.AreEqual(0, editableRange1.Id);
    Assert.AreEqual(1, editableRange2.Id);

    // Editable range starts and ends always belong to a range
    Assert.AreEqual(edRange1Start, editableRange1.EditableRangeStart);
    Assert.AreEqual(edRange1End, editableRange1.EditableRangeEnd);

    // They also inherit the ID of the entire editable range that they belong to
    Assert.AreEqual(editableRange1.Id, edRange1Start.Id);
    Assert.AreEqual(editableRange1.Id, edRange1End.Id);
    Assert.AreEqual(editableRange2.Id, edRange2Start.EditableRange.Id);
    Assert.AreEqual(editableRange2.Id, edRange2End.EditableRangeStart.EditableRange.Id);

    // If the editable range was found in a document, it will probably have something in the single user property
    // But if we make one programmatically, the property is empty by default
    Assert.AreEqual(string.Empty, editableRange1.SingleUser);

    // We have to set it ourselves if we want the ranges to belong to somebody
    editableRange1.SingleUser = "john.doe@myoffice.com";
    editableRange2.SingleUser = "jane.doe@myoffice.com";

    // Initialize a custom visitor for editable ranges that will print their contents 
    EditableRangeInfoPrinter editableRangeReader = new EditableRangeInfoPrinter();

    // Both the start and end of an editable range can accept visitors, but not the editable range itself
    edRange1Start.Accept(editableRangeReader);
    edRange2End.Accept(editableRangeReader);

    // Or, if we want to go over all the editable ranges in a document, we can get the document to accept the visitor
    editableRangeReader.Reset();
    doc.Accept(editableRangeReader);

    Console.WriteLine(editableRangeReader.ToText());
}

/// <summary>
/// Visitor implementation that prints attributes and contents of ranges.
/// </summary>
public class EditableRangeInfoPrinter : DocumentVisitor
{
    public EditableRangeInfoPrinter()
    {
        mBuilder = new StringBuilder();
    }

    public string ToText()
    {
        return mBuilder.ToString();
    }

    public void Reset()
    {
        mBuilder.Clear();
        mInsideEditableRange = false;
    }

    /// <summary>
    /// Called when an EditableRangeStart node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitEditableRangeStart(EditableRangeStart editableRangeStart)
    {
        mBuilder.AppendLine(" -- Editable range found! -- ");
        mBuilder.AppendLine("\tID: " + editableRangeStart.Id);
        mBuilder.AppendLine("\tUser: " + editableRangeStart.EditableRange.SingleUser);
        mBuilder.AppendLine("\tContents: ");

        mInsideEditableRange = true;

        // Let the visitor continue visiting other nodes
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when an EditableRangeEnd node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitEditableRangeEnd(EditableRangeEnd editableRangeEnd)
    {
        mBuilder.AppendLine(" -- End of editable range -- ");

        mInsideEditableRange = false;

        // Let the visitor continue visiting other nodes
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document. Only runs within editable ranges have their contents recorded.
    /// </summary>
    public override VisitorAction VisitRun(Run run)
    {
        if (mInsideEditableRange) mBuilder.AppendLine("\t\"" + run.Text + "\"");

        // Let the visitor continue visiting other nodes
        return VisitorAction.Continue;
    }

    private bool mInsideEditableRange;
    private readonly StringBuilder mBuilder;
}
See Also