The following example creates a new text file and writes a string to it.
using System; using System.IO; public class TextToFile { public static void Main(String[] args) { StreamWriter sr = File.CreateText("MyFile.txt"); sr.WriteLine ("This is my file"); sr.WriteLine ("I can write ints {0} or floats {1}, etc.", 1, 4.2); sr.Close(); } }