DocumentBuilderMoveToBookmark Method (String)
Moves the cursor to a bookmark.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.10
Syntax
public bool MoveToBookmark(
	string bookmarkName
)

Parameters

bookmarkName
Type: SystemString
The name of the bookmark to move the cursor to.

Return Value

Type: Boolean
True if the bookmark was found; false otherwise.
Remarks

Moves the cursor to a position just after the start of the bookmark with the specified name.

The comparison is not case-sensitive. If the bookmark was not found, false is returned and the cursor is not moved.

Inserting new text does not replace existing text of the bookmark.

Note that some bookmarks in the document are assigned to form fields. Moving to such a bookmark and inserting text there inserts the text into the form field code. Although this will not invalidate the form field, the inserted text will not be visible because it becomes part of the field code.

Examples
Shows how to move between nodes and manipulate current ones.
[C#]

Document doc = new Document(MyDir + "DocumentBuilder.WorkingWithNodes.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

// Move to a bookmark and delete the parent paragraph.
builder.MoveToBookmark("ParaToDelete");
builder.CurrentParagraph.Remove();

FindReplaceOptions options = new FindReplaceOptions
{
    MatchCase = false,
    FindWholeWordsOnly = true
};

// Move to a particular paragraph's run and replace all occurrences of "bad" with "good" within this run.
builder.MoveTo(doc.LastSection.Body.Paragraphs[0].Runs[0]);
Assert.IsTrue(builder.IsAtStartOfParagraph);
Assert.IsFalse(builder.IsAtEndOfParagraph);
builder.CurrentNode.Range.Replace("bad", "good", options);

// Mark the beginning of the document.
builder.MoveToDocumentStart();
builder.Writeln("Start of document.");

// builder.WriteLn puts an end to its current paragraph after writing the text and starts a new one
Assert.AreEqual(2, doc.FirstSection.Body.Paragraphs.Count);
Assert.IsTrue(builder.IsAtStartOfParagraph);
Assert.IsTrue(builder.IsAtEndOfParagraph);

// builder.Write doesn't end the paragraph
builder.Write("Second paragraph.");

Assert.AreEqual(2, doc.FirstSection.Body.Paragraphs.Count);
Assert.IsFalse(builder.IsAtStartOfParagraph);
Assert.IsTrue(builder.IsAtEndOfParagraph);

// Mark the ending of the document.
builder.MoveToDocumentEnd();
builder.Writeln("End of document.");

doc.Save(ArtifactsDir + "DocumentBuilder.WorkingWithNodes.doc");
See Also