How to update password in xml file

Posted by Vibheesh under C# on 5/7/2012 | Points: 10 | Views : 1560 | Status : [Member] | Replies : 1
// 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);




Responses

Posted by: perfectchourasia-9163 on: 5/7/2012 [Member] Starter | Points: 25

Up
0
Down
Your code similar to this code just get some idea~


using System;
using System.IO;

namespace FileHandlingArticleApp
{
class Program
{
static void Main(string[] args)
{
if(File.Exists("test.txt"))
{
string content = File.ReadAllText("test.txt");
Console.WriteLine("Current content of file:");
Console.WriteLine(content);
}
Console.WriteLine("Please enter new content for the file:");
string newContent = Console.ReadLine();
File.WriteAllText("test.txt", newContent);
}
}
}

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Vibheesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response