private void btnSave_Click(object sender, System.EventArgs e) { // Create an XmlDataDocument from the DataSet XmlDataDocument xdd = new XmlDataDocument((DataSet)dgCustomers.DataSource); // And save it to a disk file XmlTextWriter xtw = new XmlTextWriter(@"c:\temp\FranceCust.xml", System.Text.Encoding.UTF8); xdd.WriteTo(xtw); xtw.Flush(); xtw.Close(); MessageBox.Show(@"Wrote file c:\temp\FranceCust.xml"); }
private static void LogErrorXml(XmlDataDocument _XmlDataDocument) { _XmlFileMutex.WaitOne(); string m_LogName = InnerXmlFileName.Replace(".txt", DateTime.Now.Ticks.ToString()) + ".html"; CheckDirectory(m_LogName); XmlTextWriter xmlWriter = new XmlTextWriter(m_LogName, Encoding.ASCII); xmlWriter.Formatting = Formatting.Indented; _XmlDataDocument.WriteTo(xmlWriter); xmlWriter.Flush(); xmlWriter.Close(); _XmlFileMutex.ReleaseMutex(); }
public TraversalForm() { InitializeComponent(); try { // Load the document XmlDataDocument doc = loadXML(); if (doc == null) { return; } // Traverse the document using relational calls m_strOutput += "***Retrieving Using Relational Calls***\r\n\r\n"; retrieveAsData(doc); // Traverse the document using DOM calls m_strOutput += "\r\n\r\n***Retrieving Using DOM Calls***\r\n\r\n"; retrieveAsXml(doc); // Show the document m_strOutput += "\r\n\r\n***The XMLDataDocument ***\r\n\r\n"; StringWriter writerString = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(writerString); writer.Formatting = Formatting.Indented; doc.WriteTo(writer); writer.Flush(); m_strOutput += writerString.ToString(); textBox1.Text = m_strOutput; } catch (Exception exception) { MessageBox.Show(exception.Message); } }
/// <summary> /// Ecriture du fichier au format DataSet /// </summary> /// <param name="fileName">nom pour le fichier</param> public void SaveXmlData(string fileName) { XmlWriter xw = XmlWriter.Create(fileName, settings); xmlDataDoc.WriteTo(xw); xw.Flush(); xw.Close(); StringWriter sw = new StringWriter(); sw.Write(dataSet.GetXml()); sw.Flush(); sw.Close(); StreamWriter outfile = new StreamWriter(fileName + ".2"); outfile.Write(sw); outfile.Flush(); outfile.Close(); StringWriter sw2 = new StringWriter(); sw2.Write(dataSet.GetXmlSchema()); sw2.Flush(); sw2.Close(); StreamWriter outfile2 = new StreamWriter(fileName + ".xsd"); outfile2.Write(sw2); outfile2.Flush(); outfile2.Close(); }
/// <example>mono MonoWebPublisher.exe sample.csproj /var/www/sample-dest-publish-dir</example> static void Main(string[] args) { if (args.Length != 2 && args.Length != 3) { Console.WriteLine("Parameter not match!"); Environment.Exit(1); } var projectFile = args[0]; var destDir = args[1]; var configuration = "Release"; if (args.Length == 3) { if (!string.IsNullOrWhiteSpace(args[2])) { configuration = args[2]; } } var sourceDir = Path.GetDirectoryName(projectFile); // Find out if web.config should be transformed var webConfig = Path.Combine(sourceDir, "Web.config"); var webConfigTransform = Path.Combine(sourceDir, "Web." + configuration + ".config"); var shouldTransformWebConfig = File.Exists(webConfig) && File.Exists(webConfigTransform); //delete everything in destDir but .git folder if (Directory.Exists(destDir)) { var destDirs = Directory.GetDirectories(destDir, "*", SearchOption.TopDirectoryOnly); destDirs.ToList <string>().ForEach(n => { if (Path.GetFileName(n) != ".git") { Directory.Delete(n, true); } }); Directory.GetFiles(destDir, "*", SearchOption.TopDirectoryOnly).ToList().ForEach(File.Delete); } //copy included files var fileList = GetIncludedFiles(projectFile); fileList.ForEach(n => { bool isWebConfig = n.StartsWith("Web.") && n.EndsWith(".config"); if (!shouldTransformWebConfig || !isWebConfig) { Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(destDir, n))); File.Copy(Path.Combine(sourceDir, n), Path.Combine(destDir, n), true); } }); //copy bin folder string[] binFiles = Directory.GetFiles(Path.Combine(sourceDir, "bin")); Directory.CreateDirectory(Path.Combine(destDir, "bin")); binFiles.ToList <string>().ForEach(n => { File.Copy(n, Path.Combine(Path.Combine(destDir, "bin"), Path.GetFileName(n)), true); }); // Transform web.config if (shouldTransformWebConfig) { var xmlDoc = new XmlDataDocument { PreserveWhitespace = true }; xmlDoc.Load(webConfig); var transformation = new Microsoft.Web.XmlTransform.XmlTransformation(webConfigTransform); transformation.Apply(xmlDoc); var outputWebConfig = Path.Combine(destDir, "Web.config"); var xmlWriter = XmlWriter.Create(outputWebConfig); xmlDoc.WriteTo(xmlWriter); xmlWriter.Close(); } }