I am trying to write the user input data to the XML file in asp.net/C#. the data will type in textbox.
The C# code:
int i = 0;
protected void submit(object sender,EventArgs e)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/XMLFile1.xml"));
Console.WriteLine(xdoc);
XmlElement contact = xdoc.CreateElement("Contact");
XmlAttribute Count = xdoc.CreateAttribute("Count");
i = i + 1;
Count.Value = i.ToString();
XmlElement Name = xdoc.CreateElement("Name");
XmlText xmlName = xdoc.CreateTextNode(name.Text);
XmlElement EmailId = xdoc.CreateElement("EmailId");
XmlText xmlemail = xdoc.CreateTextNode(emailId.Text);
XmlElement Comments = xdoc.CreateElement("Comments");
XmlText xmlcomment = xdoc.CreateTextNode(comments.Text);
Name.AppendChild(xmlName);
EmailId.AppendChild(xmlemail);
Comments.AppendChild(xmlcomment);
contact.Attributes.Append(Count);
contact.AppendChild(Name);
contact.AppendChild(EmailId);
contact.AppendChild(Comments);
xdoc.DocumentElement.AppendChild(contact);
xdoc.Save(Server.MapPath("~/XMLFile1.xml"));
Response.Redirect(Request.Url.AbsoluteUri);
}
No errors are displaying not storing the values.