By appSettings-like I mean like this,
<appSettings>
<add key="myKey" value="myValue" />
</appsettings>
The result is a key-value collection that I can access like:
string v = config["myKey"];
but it is not necessarily located in app.config, so what I have is a string or a XmlNode.
NameValueFileSectionHandler.Create method apparently can do the job, but the input needs two objects, Object parent, Object configContext, in addition to a xml node, and I don't know what to pass to them.
Configuration Manager is a step-by-step user interface in Google Cloud Directory Sync (GCDS). You use Configuration Manager to create, test, and run a synchronization.
App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.
The <appSettings> element of a web. config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work.
Parse a string to a dictionary like this,
var xml = XElement.Parse("<appSettings><add key=\"myKey\" value=\"myValue\" /></appSettings>");
var dic = xml.Descendants("add").ToDictionary(x => x.Attribute("key").Value, x => x.Attribute("value").Value);
You can get the values like this,
var item = dic["myKey"];
You can also modify the values in the dictionary like this,
dic["myKey"] = "new val";
And you can convert the modified dictionary back to a XElement using this code,
var newXml = new XElement("appSettings", dic.Select(d => new XElement("add", new XAttribute("key", d.Key), new XAttribute("value", d.Value))));
You could do something like this :
Hashtable htResource = new Hashtable();
XmlDocument document = new XmlDocument();
document.LoadXml(XmlString);
foreach (XmlNode node in document.SelectSingleNode("appSettings"))
{
if ((node.NodeType != XmlNodeType.Comment) && !htResource.Contains(node.Attributes["name"].Value))
{
htResource[node.Attributes["name"].Value] = node.Attributes["value"].Value;
}
}
Then you can access the values using:
string myValue = htResource["SettingName"].ToString();
Hope that helps,
Dave
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With