static void GetAllFiles() { string path = "filepath"; var allFiles = Directory.GetFiles(path); string fileName = "file.txt"; using (FileStream fStream = File.Create(fileName)) { } using (FileStream fStream = File.Create("file.txt")) { using (StreamWriter writer = new StreamWriter(fStream, Encoding.UTF8)) { foreach (var file in allFiles) { writer.WriteLine(file); } } } }