I'm having a problem in by VB.net 2005 application. When i try to get a node
from my app.config file the node come back with "nothing". The xmldocment
loads OK, but I can't retrive a node. The app.config file is listed below
and the code is listed below that, the line with "-->>" is where i try to
get the node. Can anyone see where I'm going wrong.
A dump of the xmlDocument is listed below the code.
Note: "MyKey" is set to "Reports"
Thank,
John
jo***@iirp.coedu.usf.edu
App.config file
----------------------------------------------------------------------------------
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
</configSections>
<connectionStrings>
<add name="My.MySettings.DataConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=C:\Ingredients_Data.mdb" providerName="System.Data.OleDb" />
</connectionStrings>
<appSettings>
<add key="Reports" value="C:\current\Reports.xls" />
<add key="Calendar" value="C:\current\Calendar.xls" />
<add key="ClaimContinuum"
value="C:\current\ClaimContinuumReportBuild.xls" />
</appSettings>
</configuration>
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
Public Function Save_Config_Parameter(ByVal MyKey As String, ByVal MyValue
As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode
Dim XmlRoot As XmlNode
Dim XmlKey As XmlNode
Dim XmlValue As XmlNode
Save_Config_Parameter = ""
XmlDocument.Load(AppDomain.CurrentDomain.SetupInfo rmation.ConfigurationFile)--->> XmlNode =XmlDocument.DocumentElement.SelectSingleNode("//configuration/appSettings/add[@key=""" & MyKey & """]") If XmlNode Is Nothing Then ' The node does not exist, let's create it XmlNode = XmlDocument.CreateNode(XmlNodeType.Element, "add", "") ' Adding the Key attribute to the node, keep in mind, Xml tokens are casesensitive ' We should use 'key' instead of 'Key' XmlKey = XmlDocument.CreateNode(XmlNodeType.Attribute, "key", "") XmlKey.Value = MyKey XmlNode.Attributes.SetNamedItem(XmlKey) ' Adding the key value, once again, remember that Xml tokens are casesensitive XmlValue = XmlDocument.CreateNode(XmlNodeType.Attribute, "value", "") XmlValue.Value = MyValue XmlNode.Attributes.SetNamedItem(XmlValue) ' Add the new node to the root XmlRoot =XmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings") If Not XmlRoot Is Nothing Then XmlRoot.AppendChild(XmlNode) Else Save_Config_Parameter = "ERROR" End If Else ' ' The node exist, save the new value ' XmlNode.Attributes.GetNamedItem("value").Value = MyValue End If XmlDocument.Save(Application.ExecutablePath & ".config") XmlDocument = NothingEnd Function========================================== =============================>? XmlDocument{System.Xml.XmlDocument} Attributes: Nothing BaseURI: "file:///C:/John/bin/Debug/App.vshost.exe.config" ChildNodes: {System.Xml.XmlChildNodes} DocumentElement: {System.Xml.XmlElement} DocumentType: Nothing FirstChild: {System.Xml.XmlDeclaration} HasChildNodes: True Implementation: {System.Xml.XmlImplementation} InnerText: "" InnerXml: "<?xml version="1.0"?><configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><configSections></configSections><connectionStrings><addname="My.MyS ettings.DataConnectionString"connectionString="Pro vider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Ingred ients_Data.mdb" providerName="System.Data.OleDb"/></connectionStrings><appSettings><add key="Reports"value="C:\current\Reports.xls" /><add key="Calendar"value="C:\current\Calendar.xls" /><add key="ClaimContinuum"value="C:\current\ClaimContinu umReportBuild.xls"/></appSettings></configuration>" IsReadOnly: False Item: In order to evaluate an indexed property, the property must bequalified and the arguments must be explicitly supplied by the user. LastChild: {System.Xml.XmlElement} LocalName: "#document" Name: "#document" NamespaceURI: "" NameTable: {System.Xml.NameTable} NextSibling: Nothing NodeType: Document {9} OuterXml: "<?xml version="1.0"?><configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><configSections></configSections><connectionStrings><addname="My.MyS ettings.DataConnectionString"connectionString="Pro vider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Ingred ients_Data.mdb" providerName="System.Data.OleDb"/></connectionStrings><appSettings><add key="Reports"value="C:\current\Reports.xls" /><add key="Calendar"value="C:\current\Calendar.xls" /><add key="ClaimContinuum"value="C:\current\ClaimContinu umReportBuild.xls"/></appSettings></configuration>" OwnerDocument: Nothing ParentNode: Nothing Prefix: "" PreserveWhitespace: False PreviousSibling: Nothing SchemaInfo: {System.Xml.Schema.XmlSchemaInfo} Schemas: {System.Xml.Schema.XmlSchemaSet} Value: Nothing>