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
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
Bookmark Create(
DocumentRange range,
string name
)
Function Create(
range As DocumentRange,
name As String
) As Bookmark
| 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.
|
| Type | Description |
|---|---|
| Bookmark |
A Bookmark object specifying the created bookmark.
|
If the document already contains a bookmark with the specified name, an InvalidOperationException occurs. The BookmarkOptions.ConflictNameResolution option is not applicable in this situation.
The following code snippet creates a Bookmark and a hyperlink associated with this bookmark:
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";
}
}
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
DocumentPosition pos = document.Range.Start;
document.Bookmarks.Create(document.CreateRange(pos, 0), "Top");
//Insert the hyperlink anchored to the created bookmark:
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
// 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
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:
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
' 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