Add custom data to xml node and save xml file in C#

protected void AddNodeToXml()
        XmlDocument docXml = new XmlDocument();
        docXml.Load(Server.MapPath(@"App_Data\myXmlFile.xml")); //locate the xml file
        //Create the node to set the data
        XmlElement element = docXml.CreateElement("userprofile");
        XmlElement xmlUser = docXml.CreateElement("User");
        XmlElement xmlPass = docXml.CreateElement("Password");
        xmlUser.InnerText = this.txtUser.Text.Trim();
        xmlPass.InnerText = this.txtPass.Text.Trim();
        docXml.Save(Server.MapPath(@"App_Data\myXmlFile.xml")); //save the xml file

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.