System.Windows.Forms.RichTextBox.LoadFile Method

Loads a rich text format (RTF) or standard ASCII text file into the System.Windows.Forms.RichTextBox control.

Syntax

public void LoadFile (string path)

Parameters

path
The name and location of the file to load into the control.

Remarks

When loading a file with the RichTextBox.LoadFile(string) method, the contents of the file being loaded replace the entire contents of the System.Windows.Forms.RichTextBox control. This will cause the values of the TextBoxBase.Text and RichTextBox.Rtf properties to change. You can use this method to load a previously created text or RTF document into the control for manipulation. If you want to save the file, you can use the RichTextBox.SaveFile(string) method.

Note:

With this version of the RichTextBox.LoadFile(string) method, if the file being loaded is not an RTF document, an exception will occur. To load a different type of file such as an ASCII text file, use the other versions of this method that accept a value from the System.Windows.Forms.RichTextBoxStreamType enumeration as a parameter.

Note:

The RichTextBox.LoadFile(string) method will not open a file until a handle is created for the System.Windows.Forms.RichTextBox. Ensure that the control's handle is created before calling the RichTextBox.LoadFile(string) method.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0