Since version 2.0 of the .NET Framework, writing text to a file is made very easy:
The System.IO facility provides two useful methods:
File.WriteAllText Method [
^]
File.WriteAllLines Method [
^]
There are ready-to-use code examples at both those links.
These methods have the advantage that, unlike, using the other techniques shown here, they do not append any extra characters to the text saved to the file.
Comments:
1. any time you save whatever to a stream, or file: verify the path you will use is valid, usable, etc., before attempting to write/save.
Consider: if the file already exists if you wish to over-write it.
2. if the user is going to be selecting the save/write location at run-time: take the time to study the File and Folder Selection Dialogs, and how to configure them so the user can be guided to an appropriate choice.
3. keep in mind that Text is encoded, and may be culture-dependent. plan for that.