locked
Saving formatted text in a file using rich text box RRS feed

  • Question

  • I tried to apply formatting on the text in a rich text box and tried to save it. Next time i loaded it, the text was there but with no formatting. Can any boy help? I mean what should i do while saving the formatted text? I have searched over an internet but found a wee bit of the thing like RichTextStreamType.RTF etc but how to use it, no idea please tell me....
    Saturday, May 11, 2013 5:30 PM

Answers

  • To save the contents of the richtextbox, simply execute this line of code:

    System.IO.File.WriteAllText(pathToTheFile, richTextBox1.Rtf);

    To read the contents from the file, use this:

    richTextBox1.Rtf = System.IO.File.ReadAllText(pathToTheFile);

    • Proposed as answer by Barry Wang Thursday, May 16, 2013 8:11 AM
    • Marked as answer by Barry Wang Friday, May 17, 2013 9:53 AM
    Sunday, May 12, 2013 7:22 AM

All replies

  • The RichTextBox has two different properties to access its content: Text and Rtf.

    I suspect that you are using the Text property, which returns only the text without any formatting. Try instead the Rtf property.

    Saturday, May 11, 2013 5:58 PM
  • Thanks alot but could you please tell me how to use it while saving a file? I am developing an urdu word processing application and i have applied formatting o the text and saved it, next time when i re-loaded it, formatting was gone... No idea what to change.....
    Sunday, May 12, 2013 5:02 AM
  • To save the contents of the richtextbox, simply execute this line of code:

    System.IO.File.WriteAllText(pathToTheFile, richTextBox1.Rtf);

    To read the contents from the file, use this:

    richTextBox1.Rtf = System.IO.File.ReadAllText(pathToTheFile);

    • Proposed as answer by Barry Wang Thursday, May 16, 2013 8:11 AM
    • Marked as answer by Barry Wang Friday, May 17, 2013 9:53 AM
    Sunday, May 12, 2013 7:22 AM
  • Thanks sir.... I would try this and would let you know about results.....
    Monday, May 13, 2013 6:28 AM