Here let me know if this helps.......did not take to long to do
Type the following into your xml file using what you want for your mail server name. Any future settings you wish to add can be placed by typing another Key Name in just the same manner below the first one called "mailserver"
<?xml version="1.0" encoding="utf-8"?><Section Name="Settings"><Key Name="mailserver" Value="mail.charter.net" /></Section
Private Sub ReadXmlConfig(
Create Xml Document instanc
Dim xmlDoc As XmlDocument = New XmlDocumen
load the file.
xmlDoc.Load(Application.StartupPath & "\settings.xml")
Create an array of key nodes of your xml file. Key nodes are the various elements of the xml file that hold your settings
Dim keyNodeList As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("Key"
create an instance of a single keynode which we need to find the single key we are looking for
Dim keyNode As XmlNod
Now we loop through the nodes looking for the keynode holding our mail server value.
For Each keyNode In keyNodeLis
'Each keynode has attributes that together form a "collection." similar to an array. In this case we are seeking the "name" of the node as its attribute.
Dim attribs As XmlAttributeCollection = keyNode.Attribute
Like we did with the keynodes we create a an instance of a single "attribute" called "Name" in which we can look for our value.
Dim attrib As XmlAttribute = attribs("Name"
We are stating that in this loop if the mail server value is found we want to take the attribute of this keynode which is the mailserver value entered earlier and assign it to the string called "mailserver". Each keynode has attributes that together form a "collection." In this case we are seeking the "name" of the node as its 'attribute.
If attrib.Value = "mailserver" The
mailserversetting = attribs("Value").Value.ToString(
End I
Nex
End Su
6) In the form load event type
ReadXmlConfi
TextBox1.Text = mailserve
7) Build and run your project. You should see your mail server setting you assigned appear in the textbox on form load. After admiring your work, shut down the program
8) Now we will change the value of this key as if the end user wanted to change the name of their mail server. Under the ReadXmlConfig sub place another type the following
Sub EnterUserSettings(
Dim strOldEmailValue As Strin
Tr
Create Xml Document instanc
Dim xmlDoc As XmlDocument = New XmlDocumen
load the file.
xmlDoc.Load(Application.StartupPath & "\settings.xml"
Create an array of key nodes of your xml file. Key nodes are the various elements of the xml file that hold your settings
Dim keyNodeList As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("Key"
create an instance of a single keynode which we need to find the single key we are looking for
Dim keyNode As XmlNod
Now we loop through the nodes looking for the keynode holding our mail server value
For Each keyNode In keyNodeLis
Each keynode has attributes that together form a "collection." similar to an array. In this case we are seeking the "name" of the node as its attribute.
Dim attribs As XmlAttributeCollection = keyNode.Attribute
Like we did with the keynodes we create a an instance of a single "attribute" called "Name" in which we can look for our value.
Dim attrib As XmlAttribute = attribs("Name"
We are stating that in this loop if the mail server value is found we want to take the attribute of this keynode which is the mailserver value entered earlier and assign it to the string called "mailserver". Each keynode has attributes that together form a "collection." In this case we are seeking the "name" of the node as its 'attribute.
If attrib.Value = mailserver The
assigning the old value to a variable - in case the settings change fail
strOldValue = attribs("Value").Value.ToString(
set the new value of this key no
attribs("Value").Value = TextBox1.Tex
End I
save the xml fil
xmlDoc.Save(Application.StartupPath & "\settings.xml"
Nex
letting the user know of the chang
MsgBox("Your mail server is " & chooselocation, MsgBoxStyle.Information
Exit Sub
End If
Catch As System.IO.IOException
if saving the file failed
Select Case MessageBox.Show("There was a problem Saving the file, would you like to try another location?")
Case DialogResult.Ok
Dim od as New OpenFileDialog
od.ShowDialog
Dim FileLocation as String = od.FullName
xmlDoc.Save("Blah Blah Blah)
Case DialogResult.No
MessageBox.Show(ex.Message, "File Not Saved")
' or whatever routine you want.
End Select
MsgBox("SETTING " & mailserversetting.ToUpper & " FAILED" & vbCrLf & ex.ToString)
End Try