file dialog and richtextbox question

hi
how can i load the file that i have selected from the openfile dialog box into a richtextbox
i've tried this
Code:

openfiledialog ff=new .....;
ff.showdialog();
richbox.loadfile(ff.filename);

but it didn't work
also ,if i'm selecting a files with different extension than txt but in the file it self the data are text and it could be opened by a text editor , how can i load it too to a richtextbox " the extension is TFTP"


Answer this question

file dialog and richtextbox question

  • Jive Dadson

    the RTB control will only load plain text files or RTF documents, not word documents or other file formats

  • AFoxmore


    simple sample code...........

    this.openFileDialog1.ShowDialog();
    this.richTextBox1.LoadFile(this.openFileDialog1.FileName,RichTextBoxStreamType.RichText);

  • Peer Larsen

    it throws an exception with this message
    file format is not valid

    and marking the last line the code above

  • sprofaner

    Well, you could try to load the by defining the stream type to be RichTextBoxStreamType.PlainText or RichTextBoxStreamType.UnicodePlainText. Then the RichTextBox would not try to read it as RTF formatted file (I think...).

    richTextBox.LoadFile("filename.ext", RichTextBoxStreamType.UnicodePlainText);

    If that does not work, you could load the file first with filestream to string object, and then setting the RichTextBoxe's Text property.

  • UPV_Team

    How do you mean it does not work That looks quite ok to me... Here's a MSDN reference how to open a file.

    Do you get Exceptions, or how it does not work

  • file dialog and richtextbox question