DocumentBuilderStartBookmark Method

Marks the current position in the document as a bookmark start.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 22.1.0


public BookmarkStart StartBookmark(
	string bookmarkName


Type: SystemString
Name of the bookmark.

Return Value

Type: BookmarkStart
The bookmark start node that was just created.


Bookmarks in a document can overlap and span any range. To create a valid bookmark you need to call both StartBookmark(String) and EndBookmark(String) with the same bookmarkName parameter.

Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.


Shows how create a bookmark.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// A valid bookmark needs to have document body text enclosed by
// BookmarkStart and BookmarkEnd nodes created with a matching bookmark name.
builder.Writeln("Hello world!");

Assert.AreEqual(1, doc.Range.Bookmarks.Count);
Assert.AreEqual("MyBookmark", doc.Range.Bookmarks[0].Name);
Assert.AreEqual("Hello world!", doc.Range.Bookmarks[0].Text.Trim());
Shows how to insert a hyperlink which references a local bookmark.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Bookmarked text. ");
builder.Writeln("Text outside of the bookmark.");

// Insert a HYPERLINK field that links to the bookmark. We can pass field switches
// to the "InsertHyperlink" method as part of the argument containing the referenced bookmark's name.
builder.Font.Color = Color.Blue;
builder.Font.Underline = Underline.Single;
builder.InsertHyperlink("Link to Bookmark1", @"Bookmark1"" \o ""Hyperlink Tip", true);

doc.Save(ArtifactsDir + "DocumentBuilder.InsertHyperlinkToLocalBookmark.docx");

ExpandedSee Also