I'm developing a C # program and would like to know how to save the text of a RichTextBox
in .xml
or .html
or .txt
format.
I'm developing a C # program and would like to know how to save the text of a RichTextBox
in .xml
or .html
or .txt
format.
The question does not give details, but the simplest way to do this is by using WriteAllText()
:
File.WriteAllText(caminhoCompletoDoArquivo, seuRichTextBox.Text);
This method is ready for what you want. As its name says it writes a text in the file specified in caminhoCompletoDoArquivo
) does not have to be a variable, it can be a text with the file path, eg "c: \ myApp \ xml.txt") and it will pick up the content to be directly written to the control through the Text
property of the seuRichTextBox
object.
To read:
var texto = File.ReadAllText(caminhoCompletoDoArquivo);
Documentation for ReadAllText()
.
Of course, XML and HTML data must be in order. The recording does not guarantee anything. These methods only do the writing of a text without knowing what it means and if it is right.