// save reports private void _btnSave_Click(object sender, System.EventArgs e) { // open xml file string fileName = Path.GetDirectoryName(Application.ExecutablePath) + @"\MyReports.xml"; XmlTextWriter writer = new XmlTextWriter(fileName, System.Text.Encoding.Default); // initialize xml file writer.Formatting = Formatting.Indented; writer.Indentation = 2; writer.WriteStartDocument(); writer.WriteStartElement("Reports"); // save Customers report RenderCustomers(); c1r.ReportName = "Customers"; c1r.Save(writer); // save Employees report RenderEmployees(); c1r.ReportName = "Employees"; c1r.Save(writer); // close xml file writer.WriteEndElement(); writer.Close(); }
// save a report definition file containing the current report // or all reports in the current file private void SaveReportDefinitionFile(bool all) { // get file name SaveFileDialog sf = new SaveFileDialog(); sf.Filter = "Report Definition Files (*.xml)|*.xml"; sf.FileName = (all) ? Path.GetFileName(m_ReportFile) : lstReports.Text + ".xml"; if (sf.ShowDialog() != DialogResult.OK) { return; } // save a single report if (!all) { if (!LoadReport()) { return; } c1Report1.Save(sf.FileName); return; } // open xml file XmlTextWriter writer = new XmlTextWriter(sf.FileName, System.Text.Encoding.Default); writer.Formatting = Formatting.Indented; writer.Indentation = 2; writer.WriteStartDocument(); writer.WriteStartElement("Reports"); // save each report for (int i = 0; i < lstReports.Items.Count; i++) { lstReports.SelectedIndex = i; LoadReport(); ShowStatus(string.Format("[{0}]: Saving...", lstReports.Text)); c1Report1.Save(writer); } // close xml file writer.WriteEndElement(); // </Reports> writer.Close(); ShowStatus("Ready"); }