I am looking for a way to write to a text file in C#. I have created a form that has a textbox for firstname, lastname, phone number, date of birth. When a user hits the button I would like that info wrote out to a text file. The examples I have found don't really tell me how. So that's why I am asking on here.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
The very simplest way is just to use
File.WriteAllText
. Build the text into a single string however you want to, then useAlternatively you can open a
TextWriter
on the file to do it bit by bit:Note that you may want to be more cunning about the date of birth than just dumping the text directly from the user - you may want to validate it and write it in a standard format, for example.
Inside a ButtonClick or similar: