Skip to main content

BookmarkCollection.Create(DocumentRange, String) Method

Creates a bookmark for the specified range with the specified name and adds it to the collection.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.2.Core.dll

NuGet Package: DevExpress.RichEdit.Core

Declaration

Bookmark Create(
    DocumentRange range,
    string name
)

Parameters

Name Type Description
range DocumentRange

A DocumentRange specifying a portion of a document contained within the bookmark.

name String

A string specifying the bookmark name.

Returns

Type Description
Bookmark

A Bookmark object specifying the created bookmark.

Remarks

If the document already contains a bookmark with the specified name, an InvalidOperationException occurs. The BookmarkOptions.ConflictNameResolution option is not applicable in this situation.

Example

The following code snippet creates a Bookmark and a hyperlink associated with this bookmark:

RichEditControl_Bookmarks_Gif

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("Documents//Document.docx");
    Document document = wordProcessor.Document;

    // Create a bookmark at the document start
    DocumentRange start = document.CreateRange(document.Range.Start, 1);
    document.Bookmarks.Create(start, "Top");

    // Insert the hyperlink anchored to the created bookmark
    DocumentRange[] foundRanges = document.FindAll("To the Top", SearchOptions.CaseSensitive);
    if (foundRanges.Length > 0)
    {
        Hyperlink hyperlink = document.Hyperlinks.Create(foundRanges[0]);
        hyperlink.Anchor = "Top";
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Create(DocumentRange, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also