// xml file
<?xml version="1.0" encoding="utf-8"?>
<root>
<users>
<names username="hareesh" password="h" />
</users>
</root>
//adduser code
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Application.StartupPath + "\\UserLogin.xml");
XmlNodeList xmlnodeLst = xmlDoc.SelectNodes("/root/users/names[@username='" + txtUserName.Text + "']");
if (xmlnodeLst.Count ==0)
{
XmlNodeList xmlnodeLst1 = xmlDoc.SelectNodes("/root/users");
XmlElement xmlElement = xmlDoc.CreateElement("names");
xmlElement.SetAttribute("username", txtUserName.Text);
if (txtRepassword.Text == txtPassword.Text)
{
xmlElement.SetAttribute("password", txtPassword.Text);
}
else
{
MessageBox.Show("Password Mismatch", "AddUser", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
xmlnodeLst1[0].AppendChild(xmlElement);
xmlDoc.Save(Application.StartupPath + "\\UserLogin.xml");
MessageBox.Show("Added", "AddUser", MessageBoxButtons.OK, MessageBoxIcon.Information);
Reply |
Reply with attachment |
Alert Moderator