Reputation: 1929
I wants to load a file(.rtf) on richtextbox using this code:
OpenFileDialog OFD = new OpenFileDialog();
OFD.DefaultExt = "*.rtf";
OFD.Filter = "(*.rtf)|*.rtf;";
if (OFD.ShowDialog() == DialogResult.OK)
{
if (OFD.FileName.Length > 0)
{
richTextBox1.LoadFile(OFD.FileName); // Exception occur hare.
}
}
but i am facing an exception File format is not valid. Name of file which i want to load is MyFile.rtf This file contains simple text Hello world as content. Why this exception is going to be raised?
Upvotes: 0
Views: 258
Reputation: 685
The file represented by OFD.FileName
needs to contain RTF text. From what you're saying it's just text.
If you look at RichTextBox.LoadFile Method (String) you'll see the description for the exception you're getting:
ArgumentException The file being loaded is not an RTF document. <
Upvotes: 1
Reputation: 624
The file needs to be in rich text format. Do you have MS Word? If you do type Hello world and save that as rtf then open the file in Notepad to see an example of rtf.
Upvotes: 1