Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 21667 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > How to update password in xml file ...
Vibheesh

How to update password in xml file

Replies: 1 | Posted by: Vibheesh on 5/7/2012 | Category: C# Forums | Views: 549 | Status: [Member] | Points: 10  


// 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

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Perfect.Chourasia@Gmail.Com
Perfect.Chourasia@Gmail.Com  
Posted on: 5/7/2012 3:50:06 AM
Level: Starter | Status: [Member] | Points: 25

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://sandeep-chourasia.blogspot.com/

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

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 2:50:52 AM