Back to Devexpress

RichEditControl.LoadDocument(String) Method

wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-dot-loaddocument-x28-system-dot-string-x29.md

latest8.0 KB
Original Source

RichEditControl.LoadDocument(String) 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 the specified file. The file format is determined by its content.

Namespace : DevExpress.Xpf.RichEdit

Assembly : DevExpress.Xpf.RichEdit.v25.2.dll

NuGet Package : DevExpress.Wpf.RichEdit

Declaration

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

Parameters

NameTypeDescription
fileNameString

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

|

Returns

TypeDescription
Boolean

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

|

Remarks

The format of the document loaded from a stream is detected automatically by the built-in IFormatDetectorService service implementation. The following formats are detected:

  • DOC, DOCX, RTF, HTM, HTML, MHT, XML, EPUB;
  • ODT - non-encrypted files only.

Plain text cannot be detected automatically. To load a plain text document, use another method override with the document format DocumentFormat.PlainText as a parameter.

If the format detection fails or the passed string is null , the RichEditControl.InvalidFormatException event fires.

After loading a document, the DXRichEditDocumentSaveOptions.CurrentFileName property is set to the file name and the DXRichEditDocumentSaveOptions.CurrentFormat property is set to the detected format.

Determine a moment when the document model can be safely modified using the RichEditControl.DocumentLoaded event. Call the LoadDocument method in the Form.Loaded event handler to work with the DocumentLoaded event. Handle the DocumentLayout.DocumentFormatted event to check the loaded document’s layout.

Tip

Use LoadDocument method overloads which explicit format definition to improve performance.

The following code snippets (auto-collected from DevExpress Examples) contain references to the LoadDocument(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.

dxrichedit-for-wpf-how-to-implement-progress-indicator/CS/MainWindow.xaml.cs#L21

csharp
richEditControl1.ApplyTemplate();
richEditControl1.LoadDocument("Docs\\invitation.docx");
richEditControl1.Options.MailMerge.DataSource = new SampleData();

wpf-richedit-use-docvariable-fields/CS/MainWindow.xaml.cs#L26

csharp
richEditControl1.ApplyTemplate();
richEditControl1.LoadDocument("Docs\\invitation.docx");
richEditControl1.Options.MailMerge.DataSource = new SampleData();

dxrichedit-for-wpf-how-to-print-a-document-as-a-series-of-images/CS/SaveAsImage/MainWindow.xaml.cs#L44

csharp
{
    richEditControl1.LoadDocument("test.docx");
}

wpf-richedit-embed-a-live-chart-into-a-document/CS/RichEdit_InsertChart/MainWindow.xaml.cs#L27

csharp
InitializeComponent();
    richEditControl1.LoadDocument("Chart.rtf");
}

wpf-richedit-link-hyphenation-dictionaries/CS/DXRichEdit/MainWindow.xaml.cs#L14

csharp
richEditControl1.LoadDocument("Multimodal.docx");
var openOfficePatternStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DXRichEdit.hyph_en_US.dic");

dxrichedit-for-wpf-how-to-implement-progress-indicator/VB/MainWindow.xaml.vb#L23

vb
Me.richEditControl1.ApplyTemplate()
Me.richEditControl1.LoadDocument("Docs\invitation.docx")
Me.richEditControl1.Options.MailMerge.DataSource = New SampleData()

wpf-richedit-use-docvariable-fields/VB/MainWindow.xaml.vb#L27

vb
Me.richEditControl1.ApplyTemplate()
Me.richEditControl1.LoadDocument("Docs\invitation.docx")
Me.richEditControl1.Options.MailMerge.DataSource = New SampleData()

dxrichedit-for-wpf-how-to-print-a-document-as-a-series-of-images/VB/SaveAsImage/MainWindow.xaml.vb#L37

vb
Private Sub richEditControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.richEditControl1.LoadDocument("test.docx")
End Sub

wpf-richedit-embed-a-live-chart-into-a-document/VB/RichEdit_InsertChart/MainWindow.xaml.vb#L26

vb
InitializeComponent()
    richEditControl1.LoadDocument("Chart.rtf")
End Sub

wpf-richedit-link-hyphenation-dictionaries/VB/DXRichEdit/MainWindow.xaml.vb#L13

vb
richEditControl1.LoadDocument("Multimodal.docx")
Dim openOfficePatternStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("hyphen.dic")

See Also

Troubleshooting

RichEditControl Class

RichEditControl Members

DevExpress.Xpf.RichEdit Namespace