Handle files with C #

2

The goal is to capture two string typed into two blocks of text and save them to a file (this file is already preset and the user will not know where it is). I also want to know how to read the file information and store this information in strings.

Sample file:

    Nome: Leonardo
    Sobrenome: Vilarinho

The first and last name is what the user will type in the text blocks, and that's what I should put in the file, but I should also access this information later and store them in strings, for example, store "Leonardo" in a string name and "Vilarinho" in a string last name. And whenever the user enters another name or surname in the text block it will overwrite the file.

The file is inside the Visual Studio project, if possible, how to encrypt the file after it is saved. I've already tried using File of the IO library, but I do not understand much of it.

I tried this way:

File.Open(dados.txt, FileMode TextWriter);
 File.WriteAllText("Nome: %s\nSobrenome: %s", usuario, sobrenome );

But as you can see I do not understand anything about files, and the code is all wrong, I've seen several videos, but none of them look like my goal. I did not even try to get the file information later, since I could not even save it.

    
asked by anonymous 27.06.2015 / 19:06

1 answer

1

Take a closer look at the MSDN , the method .WriteAllText

27.06.2015 / 19:27