public void SaveToFile(string directoryPath, string fileName, WorkReport report) { if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(Path.Combine(directoryPath, fileName), report.ToString()); }
static void Main(string[] args) { var report = new WorkReport(); report.AddEntry(new WorkReportEntry { ProjectCode = "123Ds", ProjectName = "Project1", SpentHours = 5 }); report.AddEntry(new WorkReportEntry { ProjectCode = "987Fc", ProjectName = "Project2", SpentHours = 3 }); Console.WriteLine(report.ToString()); var saver = new FileSaver(); saver.SaveToFile(@"Reports", "WorkReport.txt", report); StandardMessage.EndApplication(); }