BookmarkStart Class |
Namespace: Aspose.Words
The BookmarkStart type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | BookmarkStart |
Initializes a new instance of the BookmarkStart class.
|
Name | Description | |
---|---|---|
![]() ![]() | Bookmark |
Gets the facade object that encapsulates this bookmark start and end.
|
![]() ![]() | Document |
Gets the document to which this node belongs.
(Inherited from Node.) |
![]() ![]() | IsComposite |
Returns true if this node can contain other nodes.
(Inherited from Node.) |
![]() ![]() | Name |
Gets or sets the bookmark name.
|
![]() ![]() | NextSibling |
Gets the node immediately following this node.
(Inherited from Node.) |
![]() ![]() | NodeType |
Returns BookmarkStart.
(Overrides NodeNodeType.) |
![]() ![]() | ParentNode |
Gets the immediate parent of this node.
(Inherited from Node.) |
![]() ![]() | PreviousSibling |
Gets the node immediately preceding this node.
(Inherited from Node.) |
![]() ![]() | Range |
Returns a Range object that represents the portion of a document that is contained in this node.
(Inherited from Node.) |
Name | Description | |
---|---|---|
![]() ![]() | Accept |
Accepts a visitor.
(Overrides NodeAccept(DocumentVisitor).) |
![]() ![]() | Clone | (Inherited from Node.) |
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetAncestor(Type) |
Gets the first ancestor of the specified object type.
(Inherited from Node.) |
![]() ![]() | GetAncestor(NodeType) |
Gets the first ancestor of the specified NodeType.
(Inherited from Node.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() ![]() | GetText |
Returns an empty string.
(Overrides NodeGetText.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | NextPreOrder |
Gets next node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | PreviousPreOrder |
Gets the previous node according to the pre-order tree traversal algorithm.
(Inherited from Node.) |
![]() ![]() | Remove |
Removes itself from the parent.
(Inherited from Node.) |
![]() | ToString | (Inherited from Object.) |
![]() ![]() | ToString(SaveFormat) |
Exports the content of the node into a string in the specified format.
(Inherited from Node.) |
![]() ![]() | ToString(SaveOptions) |
Exports the content of the node into a string using the specified save options.
(Inherited from Node.) |
A complete bookmark in a Word document consists of a BookmarkStart and a matching BookmarkEnd with the same bookmark name.
BookmarkStart and BookmarkEnd are just markers inside a document that specify where the bookmark starts and ends.
Use the Bookmark class as a "facade" to work with a bookmark as a single object.
public void CreateUpdateAndPrintBookmarks() { // Create a document with 3 bookmarks: "MyBookmark 1", "MyBookmark 2", "MyBookmark 3" Document doc = CreateDocumentWithBookmarks(); BookmarkCollection bookmarks = doc.Range.Bookmarks; // Check that we have 3 bookmarks Assert.AreEqual(3, bookmarks.Count); // Look at initial values of our bookmarks PrintAllBookmarkInfo(bookmarks); // Obtain bookmarks from a bookmark collection by index/name and update their values bookmarks[0].Name = "Updated name of " + bookmarks[0].Name; bookmarks["MyBookmark 2"].Text = "Updated text content of " + bookmarks[1].Name; // Remove the latest bookmark // The bookmarked text is not deleted bookmarks[2].Remove(); bookmarks = doc.Range.Bookmarks; // Check that we have 2 bookmarks after the latest bookmark was deleted Assert.AreEqual(2, bookmarks.Count); // Look at updated values of our bookmarks PrintAllBookmarkInfo(bookmarks); } /// <summary> /// Create a document with bookmarks using the start and end nodes. /// </summary> private static Document CreateDocumentWithBookmarks() { DocumentBuilder builder = new DocumentBuilder(); Document doc = builder.Document; // An empty document has just one empty paragraph by default Paragraph p = doc.FirstSection.Body.FirstParagraph; // Add several bookmarks to the document for (int i = 1; i <= 3; i++) { string bookmarkName = "MyBookmark " + i; p.AppendChild(new Run(doc, "Text before bookmark.")); p.AppendChild(new BookmarkStart(doc, bookmarkName)); p.AppendChild(new Run(doc, "Text content of " + bookmarkName)); p.AppendChild(new BookmarkEnd(doc, bookmarkName)); p.AppendChild(new Run(doc, "Text after bookmark.\r\n")); } return builder.Document; } /// <summary> /// Use an iterator and a visitor to print info of every bookmark from within a document. /// </summary> private static void PrintAllBookmarkInfo(BookmarkCollection bookmarks) { // Create a DocumentVisitor BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter(); // Get the enumerator from the document's BookmarkCollection and iterate over the bookmarks using (IEnumerator<Bookmark> enumerator = bookmarks.GetEnumerator()) { while (enumerator.MoveNext()) { Bookmark currentBookmark = enumerator.Current; // Accept our DocumentVisitor it to print information about our bookmarks if (currentBookmark != null) { currentBookmark.BookmarkStart.Accept(bookmarkVisitor); currentBookmark.BookmarkEnd.Accept(bookmarkVisitor); // Prints a blank line Console.WriteLine(currentBookmark.BookmarkStart.GetText()); } } } } /// <summary> /// Visitor that prints bookmark information to the console. /// </summary> public class BookmarkInfoPrinter : DocumentVisitor { public override VisitorAction VisitBookmarkStart(BookmarkStart bookmarkStart) { Console.WriteLine("BookmarkStart name: \"{0}\", Content: \"{1}\"", bookmarkStart.Name, bookmarkStart.Bookmark.Text); return VisitorAction.Continue; } public override VisitorAction VisitBookmarkEnd(BookmarkEnd bookmarkEnd) { Console.WriteLine("BookmarkEnd name: \"{0}\"", bookmarkEnd.Name); return VisitorAction.Continue; } }