officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-fieldcollection-dot-create-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-string-x29.md
Adds a field specified by its code to the field collection.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Field Create(
DocumentPosition start,
string code
)
Function Create(
start As DocumentPosition,
code As String
) As Field
| Name | Type | Description |
|---|---|---|
| start | DocumentPosition |
A DocumentPosition at which the field is inserted.
| | code | String |
A string specifying the field’s code.
|
| Type | Description |
|---|---|
| Field |
A Field object specifying the newly created field.
|
The code snippet below uses the SYMBOL field to add a check mark (✔) to the document:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Create the "SYMBOL" field.
document.Fields.Create(document.Range.Start, "SYMBOL 252 \\f Wingdings \\s 28");
// Finalize to edit the document.
document.EndUpdate();
// Update all fields in the main document body.
document.Fields.Update();
// Save the document to the file.
document.SaveDocument("Result.docx", DocumentFormat.Docx);
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...
Using wordProcessor As New RichEditDocumentServer()
' Access a document.
Dim document As Document = wordProcessor.Document
' Start to edit the document.
document.BeginUpdate()
' Create the "SYMBOL" field.
document.Fields.Create(document.Range.Start, "SYMBOL 252 \f Wingdings \s 28")
' Finalize to edit the document.
document.EndUpdate()
' Update all fields in the main document body.
document.Fields.Update()
' Save the document to the file.
document.SaveDocument("Result.docx", DocumentFormat.Docx)
End Using
The following code snippets (auto-collected from DevExpress Examples) contain references to the Create(DocumentPosition, 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/DocumentProperties.cs#L20
document.Fields.Create(document.AppendText("\nAUTHOR: ").End, "AUTHOR");
document.Fields.Create(document.AppendText("\nTITLE: ").End, "TITLE");
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/DocumentFieldActions.cs#L16
document.BeginUpdate();
document.Fields.Create(document.CaretPosition, "DATE");
document.Fields.Update();
word-document-api-examples/CS/CodeExamples/FieldActions.cs#L28
// Create the "DATE" field.
document.Fields.Create(document.Range.Start, "DATE");
winforms-richedit-table-of-contents-practical-guide/CS/Form1.cs#L63
SearchForTOCEntries(delegate(DocumentPosition location, int level) {
Document.Fields.Create(location, string.Format("TC \"{0}\" \\f {1} \\l {2}",
Document.GetText(Document.Paragraphs.Get(location).Range), "defaultGroup", level));
word-processing-table-of-contents-practical-guide/CS/Program.cs#L84
SearchForTOCEntries(document, delegate (DocumentPosition location, int level) {
document.Fields.Create(location, string.Format("TC \"{0}\" \\f {1} \\l {2}",
document.GetText(document.Paragraphs.Get(location).Range), "defaultGroup", level));
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Field.vb#L18
'Create a DATE field at the caret position
document.Fields.Create(caretPosition, "DATE")
document.Fields.Update()
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/DocumentFieldActions.vb#L13
document.BeginUpdate()
document.Fields.Create(document.CaretPosition, "DATE")
document.Fields.Update()
word-document-api-examples/VB/CodeExamples/FieldActions.vb#L28
' Create the "DATE" field.
document.Fields.Create(document.Range.Start, "DATE")
' Update all fields in the main document body.
winforms-richedit-table-of-contents-practical-guide/VB/Form1.vb#L66
Private Sub AddTCFields()
SearchForTOCEntries(Sub(ByVal location, ByVal level) Document.Fields.Create(location, String.Format("TC ""{0}"" \f {1} \l {2}", Document.GetText(Document.Paragraphs.Get(location).Range), "defaultGroup", level)))
End Sub
word-processing-table-of-contents-practical-guide/VB/Program.vb#L80
SearchForTOCEntries(document, Function(ByVal location As DocumentPosition, ByVal level As Integer)
document.Fields.Create(location, String.Format("TC ""{0}"" \f {1} \l {2}",
document.GetText(document.Paragraphs.[Get](location).Range), "defaultGroup", level))
See Also