Back to Devexpress

RichEditDocumentServer.LoadDocument(String, DocumentFormat) Method

officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserver-dot-loaddocument-x28-system-dot-string-devexpress-dot-xtrarichedit-dot-documentformat-x29.md

latest7.7 KB
Original Source

RichEditDocumentServer.LoadDocument(String, DocumentFormat) Method

SECURITY-RELATED CONSIDERATIONS

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

Declaration

csharp
public virtual bool LoadDocument(
    string fileName,
    DocumentFormat documentFormat
)
vb
Public Overridable Function LoadDocument(
    fileName As String,
    documentFormat As DocumentFormat
) As Boolean

Parameters

NameTypeDescription
fileNameString

A string specifying the file to load (including the full path).

| | documentFormat | DocumentFormat |

One of the DocumentFormat enumeration members, indicating the document format.

|

Returns

TypeDescription
Boolean

true , if the document is successfully loaded; otherwise, false.

|

Remarks

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

csharp
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);

word-document-api-insert-inline-pictures/CS/Program.cs#L20

csharp
{
    wordProcessor.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf);
    Document document = wordProcessor.Document;

word-document-api-use-docvariable-fields/CS/Program.cs#L18

csharp
RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
wordProcessor.LoadDocument("Docs\\invitation.docx", DocumentFormat.OpenXml);

word-document-api-use-printablecomponentlink-to-print-document/CS/PrintingSystem/Form1.cs#L21

csharp
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

csharp
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);

word-document-api-examples/VB/CodeExamples/InlinePictureActions.vb#L20

vb
' 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

vb
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

vb
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

vb
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

vb
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Access a document.

See Also

RichEditDocumentServer Class

RichEditDocumentServer Members

DevExpress.XtraRichEdit Namespace