|
-
May 14th, 2009, 03:13 AM
#1
Thread Starter
Fanatic Member
Read a node in config xml
I have the following in my confid settings:
Code:
<configuration>
<appSettings>
<add key="STAMP" value="999" />
</appSettings>
</configuration>
If I want to alter the node 'STAMP' I do the following:
Code:
XmlElement elementStamp = (XmlElement)doc.SelectSingleNode("/configuration/appSettings/add[@key='STAMP']");
elementStamp.SetAttribute("value", "999");
What I want to know, and I know this is silly, but how do I read it?
-
May 14th, 2009, 03:41 AM
#2
Re: Read a node in config xml
You could do
Code:
Dim myValue As String = System.Configuration.ConfigurationManager.AppSettings("STAMP")
Please mark you thread resolved using the Thread Tools as shown
-
May 20th, 2009, 12:58 AM
#3
Re: Read a node in config xml
You should be using the ConfigurationManager class to access the config file to write too. If you follow the CodeBank link in my signature you can see how it's done in my Protected Configuration thread. I don't have a C# version of that code but the principles are exactly the same.
-
May 27th, 2009, 01:01 PM
#4
Hyperactive Member
Re: Read a node in config xml
I used to do this with the 1.1 framework, I think there is another class for this now but never had any reason to use it. However at least this worked:
Code:
The configuration file:
<!--Configuration File - Darren Rattansingh -->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="nameval" value="192.122.0.5"/>
</appSettings>
</configuration>
C# code:
using System.Configuration;
// this will output the value of the key.
MessageBox.show(ConfigurationSettings.AppSettings["nameval"].ToString());
But as i said, I think this way has been replaced by another class. So you could do some research if necessary. The last time I checked however, you could still manipulate xml files with the 3.5 framework this way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|