XML

Read and Edit xml file

XML

Read and Edit xml file

<?xml version=”1.0″ encoding=”utf-8″?>
<appSettings>
<EmailAddress></EmailAddress>
<UserName></UserName>
<Password></Password>
<SMTPserver>smtp.gmail.com</SMTPserver>
<Port>
</Port>
<ssl>False</ssl>
</appSettings>

Code:

public void GetEmailsetting()
{
vidDocument.Load(XmlPath);
// this is how you get all the video nodes, perhaps to bind them or iterate over them
XmlNodeList videos = vidDocument.SelectNodes(“/appSettings”);
XmlNode xmlappsetting = (XmlNode)videos.Item(0);
XmlNodeList Childnode = (xmlappsetting).ChildNodes;
EmailAddress = Childnode.Item(0).InnerText;
UserName = Childnode.Item(1).InnerText;
Password = Childnode.Item(2).InnerText;
SMTPserver = Childnode.Item(3).InnerText;
port = Childnode.Item(4).InnerText;
ssl = Convert.ToBoolean(Childnode.Item(5).InnerText);
// this would select all title elements

}

public void SetEmailsetting()
{
vidDocument.Load(XmlPath);
// this is how you get all the video nodes, perhaps to bind them or iterate over them
XmlNodeList videos = vidDocument.SelectNodes(“/appSettings”);
XmlNode xmlappsetting = (XmlNode)videos.Item(0);
XmlNodeList Childnode = (xmlappsetting).ChildNodes;
Childnode.Item(0).InnerText = EmailAddress;
Childnode.Item(1).InnerText = UserName;
Childnode.Item(2).InnerText = Password;
Childnode.Item(3).InnerText = SMTPserver;
Childnode.Item(4).InnerText = port;
Childnode.Item(5).InnerText = ssl.ToString();
vidDocument.Save(XmlPath);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.