public void SaveToFile(string directoryPath, string fileName, WorkReport report)
        {
            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            File.WriteAllText(Path.Combine(directoryPath, fileName), report.ToString());
        }
示例#2
0
        static void Main(string[] args)
        {
            var report = new WorkReport();

            report.AddEntry(new WorkReportEntry
            {
                ProjectCode = "001",
                ProjectName = "Project 1",
                SpentHours  = 100
            });
            report.AddEntry(new WorkReportEntry
            {
                ProjectCode = "002",
                ProjectName = "Project 2",
                SpentHours  = 150
            });

            Console.Write(report.ToString());

            var fileSaver = new FileSaver();

            fileSaver.SaveToFile(@"Reports", "WorkReport.txt", report);
        }