I am developing an application in .NET Framework using C#, in my application I have the necessity of getting a value from an XML file. I have written the following code, to get the value when the key is provided by searching for the key in the XML file.
XmlDocument appSettingsDoc = new XmlDocument();
appSettingsDoc.Load(Assembly.GetExecutingAssembly().Location + ".config");
XmlNode node = appSettingsDoc.SelectSingleNode("//appSettings");
XmlElement value = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));
return (value.GetAttribute("value"));
But I am unable to get the key name when the value is given, for example, if the file contains
`<add key="keyname" value="keyvalue" />`
and if I provide “keyvalue” I want to get “keyname”. I know that I am reading from the appconfig file and there is an other way also(i.e using configurationmanager) but I want to read it using XML.
Please help me out.
Thanks,
Bibhu
try using this method