Tuesday, 7 August 2012

Writing the Data To the XML File


Writing the Data To the XML File


string fileName = RemoveSpecialCharacters(DateTime.Now.ToString()) + FileUpload1.FileName;
XmlWriterSettings st = new XmlWriterSettings();
st.Indent = true; ;
st.OmitXmlDeclaration = true;
st.Encoding = Encoding.ASCII;

// to append to the existing files
try
{
XElement xml = XElement.Load(Server.MapPath(".\\XML\\data.xml"));
xml.Add(new XElement("Software", new XAttribute("Name", TextBox1.Text),
new XElement("Version", TextBox2.Text),

xml.Save(Server.MapPath(".\\XML\\data.xml"));
}
catch(Exception ex)
{
using (XmlWriter writer = XmlWriter.Create(Server.MapPath(".\\XML\\data.xml"), st))
{
writer.WriteComment("This xml file for the Database Purpose ");

writer.WriteStartElement("Version");
writer.WriteValue(TextBox2.Text);
writer.WriteEndElement();
writer.Flush();
}
}

No comments:

Post a Comment