Tuesday, January 15, 2008

Create a XML File Using C#.Net

To create a XML file Using C#.net:

Include the System.XML name space:
using System.xml;

Define the path to create the XMl file:
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString() + @"\Sample.xml";


Create the XML file using the code below.
XmlTextWriter xmlWriter = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("Root");
xmlWriter.Close();
xmlDocument.Load(filePath);

No comments: