DocumentBuilderMoveToBookmark Method (String)
public bool MoveToBookmark( string bookmarkName )
Public Function MoveToBookmark ( bookmarkName As String ) As Boolean
public: bool MoveToBookmark( String^ bookmarkName )
member MoveToBookmark : bookmarkName : string -> bool
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.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Start a bookmark and add content to it using a DocumentBuilder builder.StartBookmark("MyBookmark"); builder.Writeln("Bookmark contents."); builder.EndBookmark("MyBookmark"); // The node that the DocumentBuilder is currently at is past the boundaries of the bookmark Assert.AreEqual(doc.Range.Bookmarks.BookmarkEnd, builder.CurrentParagraph.FirstChild); // If we wish to revise the content of our bookmark with the DocumentBuilder, we can move back to it like this builder.MoveToBookmark("MyBookmark"); // Now we're located between the bookmark's BookmarkStart and BookmarkEnd nodes, so any text the builder adds will be within it Assert.AreEqual(doc.Range.Bookmarks.BookmarkStart, builder.CurrentParagraph.FirstChild); // We can move the builder to an individual node, // which in this case will be the first node of the first paragraph, like this builder.MoveTo(doc.FirstSection.Body.FirstParagraph.GetChildNodes(NodeType.Any, false)); Assert.AreEqual(NodeType.BookmarkStart, builder.CurrentNode.NodeType); Assert.IsTrue(builder.IsAtStartOfParagraph); // A shorter way of moving the very start/end of a document is with these methods builder.MoveToDocumentEnd(); Assert.IsTrue(builder.IsAtEndOfParagraph); builder.MoveToDocumentStart(); Assert.IsTrue(builder.IsAtStartOfParagraph);