Back to Devexpress

BookmarkCollection.Create(DocumentRange, String) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-bookmarkcollection-dot-create-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-system-dot-string-x29.md

latest7.6 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Bookmark Create(
    DocumentRange range,
    string name
)
vb
Function Create(
    range As DocumentRange,
    name As String
) As Bookmark

Parameters

NameTypeDescription
rangeDocumentRange

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

| | name | String |

A string specifying the bookmark name.

|

Returns

TypeDescription
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:

csharp
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";
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()
    wordProcessor.LoadDocument("Documents//Document.docx")
    Dim document As Document = wordProcessor.Document

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

    ' Insert the hyperlink anchored to the created bookmark
    Dim foundRanges() As DocumentRange = document.FindAll("To the Top", SearchOptions.CaseSensitive)
    If foundRanges.Length > 0 Then
        Dim hyperlink As Hyperlink = document.Hyperlinks.Create(foundRanges(0))
        hyperlink.Anchor = "Top"
    End If
End Using

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.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/BookmarksAndHyperlinks.cs#L19

csharp
DocumentPosition pos = document.Range.Start;
 document.Bookmarks.Create(document.CreateRange(pos, 0), "Top");
//Insert the hyperlink anchored to the created bookmark:

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/BookmarksAndHyperlinksActions.cs#L19

csharp
DocumentPosition pos = document.Range.Start;
document.Bookmarks.Create(document.CreateRange(pos, 0), "Top");
//Insert the hyperlink anchored to the created bookmark:

word-document-api-examples/CS/CodeExamples/BookmarksAndHyperlinks.cs#L26

csharp
// Create a bookmark at the start document position.
document.Bookmarks.Create(document.CreateRange(document.Range.Start, 0), "Top");

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/BookmarksAndHyperlinks.vb#L18

vb
Dim pos As DevExpress.XtraRichEdit.API.Native.DocumentPosition = document.Range.Start
document.Bookmarks.Create(document.CreateRange(pos, 0), "Top")
'Insert the hyperlink anchored to the created bookmark:

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/BookmarksAndHyperlinksActions.vb#L16

vb
Dim pos As DocumentPosition = document.Range.Start
document.Bookmarks.Create(document.CreateRange(pos, 0), "Top")
'Insert the hyperlink anchored to the created bookmark:

word-document-api-examples/VB/CodeExamples/BookmarksAndHyperlinks.vb#L27

vb
' Create a bookmark at the start document position.
document.Bookmarks.Create(document.CreateRange(document.Range.Start, 0), "Top")
' Create a hyperlink that navigates to the created bookmark.

See Also

Bookmarks

Remove(Bookmark)

Select(Bookmark)

BookmarkCollection Interface

BookmarkCollection Members

DevExpress.XtraRichEdit.API.Native Namespace