This example writes the contents of a string to a text file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); StringBuilder sb = new StringBuilder(); foreach (string txtName in Directory.EnumerateFiles(mydocpath,"*.txt")) { using (StreamReader sr = new StreamReader(txtName)) { sb.AppendLine(txtName.ToString()); sb.AppendLine("= = = = = ="); sb.Append(sr.ReadToEnd()); sb.AppendLine(); sb.AppendLine(); } } using (StreamWriter outfile = new StreamWriter(mydocpath + @"\AllTxtFiles.txt")) { outfile.Write(sb.ToString()); } |