How to save text in xml or txt or html file?

4

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.

    
asked by anonymous 17.08.2015 / 22:16

1 answer

3

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.

    
17.08.2015 / 22:41