officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserver-dot-loaddocument-x28-system-dot-string-devexpress-dot-xtrarichedit-dot-documentformat-x29.md
Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.
Loads a document from a file, specifying the document format.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
public virtual bool LoadDocument(
string fileName,
DocumentFormat documentFormat
)
Public Overridable Function LoadDocument(
fileName As String,
documentFormat As DocumentFormat
) As Boolean
| Name | Type | Description |
|---|---|---|
| fileName | String |
A string specifying the file to load (including the full path).
| | documentFormat | DocumentFormat |
One of the DocumentFormat enumeration members, indicating the document format.
|
| Type | Description |
|---|---|
| Boolean |
true , if the document is successfully loaded; otherwise, false.
|
If the document is in a different format than specified or the passed string value is null , the RichEditDocumentServer.InvalidFormatException event fires.
After loading a document, the DocumentSaveOptions.CurrentFileName property is set to the file name and the DocumentSaveOptions.CurrentFormat property is set to the specified format.
Tip
Determine a moment when the document model can be safely modified using the RichEditDocumentServer.DocumentLoaded event. Handle the DocumentLayout.DocumentFormatted event to check the loaded document’s layout.
The following code snippets (auto-collected from DevExpress Examples) contain references to the LoadDocument(String, DocumentFormat) 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.
word-document-api-examples/CS/CodeExamples/BookmarksAndHyperlinks.cs#L17
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
word-document-api-insert-inline-pictures/CS/Program.cs#L20
{
wordProcessor.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf);
Document document = wordProcessor.Document;
word-document-api-use-docvariable-fields/CS/Program.cs#L18
RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
wordProcessor.LoadDocument("Docs\\invitation.docx", DocumentFormat.OpenXml);
word-document-api-use-printablecomponentlink-to-print-document/CS/PrintingSystem/Form1.cs#L21
RichEditDocumentServer srv = new RichEditDocumentServer();
srv.LoadDocument("Grimm.docx", DocumentFormat.OpenXml);
// Insert a field displaying the current date/time into the document header.
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Formatting.cs#L145
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
word-document-api-examples/VB/CodeExamples/InlinePictureActions.vb#L20
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Access a document.
word-document-api-insert-inline-pictures/VB/Program.vb#L13
Using wordProcessor As New RichEditDocumentServer()
wordProcessor.LoadDocument("Texts\InlinePictures.rtf", DocumentFormat.Rtf)
Dim document As Document = wordProcessor.Document
word-document-api-use-docvariable-fields/VB/Program.vb#L12
Dim wordProcessor As RichEditDocumentServer = New RichEditDocumentServer()
wordProcessor.LoadDocument("Docs\invitation.docx", DocumentFormat.OpenXml)
word-document-api-use-printablecomponentlink-to-print-document/VB/PrintingSystem/Form1.vb#L21
Dim srv As RichEditDocumentServer = New RichEditDocumentServer()
srv.LoadDocument("Grimm.docx", DocumentFormat.OpenXml)
' Insert a field displaying the current date/time into the document header.
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Formatting.vb#L126
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Access a document.
See Also