Click or drag to resize

BookmarkCollection Class

Represents a collection of Bookmarks.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentBookmarkCollection

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.3.11
Syntax
public sealed class BookmarkCollection : ICollection<Bookmark>, 
	IEnumerable<Bookmark>, IEnumerable

The BookmarkCollection type exposes the following members.

Properties
 NameDescription
Public propertyCount Gets the number of Bookmarks contained in the BookmarkCollection.
Public propertyItemInt32 Gets the Bookmark at the specified index.
Public propertyCode exampleItemString Gets the Bookmark with the specified name.
Top
Methods
 NameDescription
Public methodClear Removes all items from the ICollectionT.
Public methodContains Determines whether the ICollectionT contains a specific value.
Public methodCopyTo Copies the elements of the ICollectionT to an Array, starting at a particular Array index.
Public methodGetEnumerator Gets an enumerator that iterates through the collection.
Public methodIndexOf Determines the index of a specific item in the IListT.
Public methodRemove Removes the first occurrence of a specific object from the ICollectionT.
Public methodRemoveAt Removes the IListT item at the specified index.
Top
Example

See Developer Guide: How add a text bounded by BookmarkStart and BookmarkEnd

How add a text bounded by BookmarkStart and BookmarkEnd using C#
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            AddBookmarks();
        }

        /// <summary>
        /// How add a text bounded by BookmarkStart and BookmarkEnd. 
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/bookmarks.php
        /// </remarks>        
        public static void AddBookmarks()
        {
            // P.S. If you are using MS Word, to display bookmarks:
            // File -> Options -> Advanced -> On the "Show document content" check "Show bookmarks".
            string documentPath = @"Bookmarks.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Add text bounded by BookmarkStart and BookmarkEnd.
            dc.Sections.Add(
            new Section(dc,
                new Paragraph(dc,
                    new Run(dc, "Text before bookmark. "),
                    new BookmarkStart(dc, "SimpleBookmark"),
                    new Run(dc, "Text inside bookmark."),
                    new BookmarkEnd(dc, "SimpleBookmark"),
                    new Run(dc, " Text after bookmark.")),
                new Paragraph(dc,
                    new SpecialCharacter(dc, SpecialCharacterType.PageBreak),
                    new Hyperlink(dc, "SimpleBookmark", "Go to Simple Bookmark.") { IsBookmarkLink = true })));

            // Modify text inside bookmark.
            dc.Bookmarks["SimpleBookmark"].GetContent(false).Replace("Some text inside bookmark.");

            // Let's save our document into DOCX format.
            dc.Save(documentPath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How add a text bounded by BookmarkStart and BookmarkEnd using VB.Net
Imports SautinSoft.Document

Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
            AddBookmarks()
        End Sub
        ''' Get your free 30-day key here:   
        ''' https://sautinsoft.com/start-for-free/
        ''' <summary>
        ''' How add a text bounded by BookmarkStart and BookmarkEnd. 
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/bookmarks.php
        ''' </remarks>        
        Public Shared Sub AddBookmarks()
            ' P.S. If you are using MS Word, to display bookmarks:
            ' File -> Options -> Advanced -> On the "Show document content" check "Show bookmarks".
            Dim documentPath As String = "Bookmarks.docx"

            ' Let's create a new document.
            Dim dc As New DocumentCore()

            ' Add text bounded by BookmarkStart and BookmarkEnd.
            dc.Sections.Add(New Section(dc, New Paragraph(dc, New Run(dc, "Text before bookmark. "), New BookmarkStart(dc, "SimpleBookmark"), New Run(dc, "Text inside bookmark."), New BookmarkEnd(dc, "SimpleBookmark"), New Run(dc, " Text after bookmark.")), New Paragraph(dc, New SpecialCharacter(dc, SpecialCharacterType.PageBreak), New Hyperlink(dc, "SimpleBookmark", "Go to Simple Bookmark.") With {.IsBookmarkLink = True})))

            ' Modify text inside bookmark.
            dc.Bookmarks("SimpleBookmark").GetContent(False).Replace("Some text inside bookmark.")

            ' Let's save our document into DOCX format.
            dc.Save(documentPath)

            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also