public void MakeReport(string reportFileName, string sourceDirectoryName, ICreateReportOptions options) { var di = new DirectoryInfo(sourceDirectoryName); if (!di.Exists) { throw new DirectoryNotFoundException(sourceDirectoryName); } var fi = new FileInfo(reportFileName); if (fi.Exists) { fi.Delete(); } File.Copy(reportTemplate, reportFileName); var tableContent = new TableContent("Files"); foreach (var fileInfo in di.GetFiles()) { tableContent.AddRow( new FieldContent("FileName", fileInfo.Name), new FieldContent("FileSize", fileInfo.Length.ToString())); } var valuesToFill = new Content( new FieldContent("DirectoryName", di.Name), new FieldContent("DirectoryPath", di.Parent.FullName), tableContent ); using (var outputDocument = new TemplateProcessor(reportFileName) .SetRemoveContentControls(true)) { outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } if (options.OpenAfterCreate) { ProcessStartInfo info = new ProcessStartInfo() { FileName = reportFileName, UseShellExecute = true }; Process.Start(info); } }
public void MakeReport(string reportFileName, string sourceFileName, ICreateReportOptions options) { FileInfo fi = new FileInfo(sourceFileName); if (!fi.Exists) { throw new FileNotFoundException(sourceFileName); } fi = new FileInfo(reportFileName); if (fi.Exists) { fi.Delete(); } File.Copy(reportTemplate, reportFileName); var valuesToFill = new Content( new FieldContent("FileName", fi.Name), new FieldContent("FilePath", Path.GetDirectoryName(fi.FullName)), new FieldContent("FileSize", fi.Length.ToString()), new FieldContent("ReadOnlyAttribute", fi.Attributes.HasFlag(FileAttributes.ReadOnly) ? "true" : "false"), new FieldContent("HiddenAttribute", fi.Attributes.HasFlag(FileAttributes.Hidden) ? "true" : "false"), new FieldContent("ArchiveAttribute", fi.Attributes.HasFlag(FileAttributes.Archive) ? "true" : "false"), new FieldContent("SystemAttribute", fi.Attributes.HasFlag(FileAttributes.System) ? "true" : "false") ); using (var outputDocument = new TemplateProcessor(reportFileName) .SetRemoveContentControls(true)) { outputDocument.FillContent(valuesToFill); outputDocument.SaveChanges(); } if (options.OpenAfterCreate) { ProcessStartInfo info = new ProcessStartInfo() { FileName = reportFileName, UseShellExecute = true }; Process.Start(info); } }