A4LGSharedFunctions.ConfigUtil.GetConfigValue C# (CSharp) Method

GetConfigValue() public static method

public static GetConfigValue ( string keyname, bool defaultValue ) : bool
keyname string
defaultValue bool
return bool
        public static bool GetConfigValue(string keyname, bool defaultValue)
        {
            XmlDocument oXml = null;
            XmlNodeList oList = null;
            try
            {
                string pConfigFile = GetConfigFile();
                string keyvalue = "";
                if (File.Exists(pConfigFile))
                {
                    //NameValueCollection AppSettings = new NameValueCollection();
                    oXml = new XmlDocument();

                    oXml.Load(pConfigFile);

                    oList = oXml.GetElementsByTagName("appSettings");
                    if (oList == null) return defaultValue;

                    //AppSettings = new NameValueCollection();
                    foreach (XmlNode oNode in oList)
                    {
                        foreach (XmlNode oKey in oNode.ChildNodes)
                        {
                            if ((oKey != null) && (oKey.Attributes != null))
                            {
                                if (oKey.Attributes["key"].Value.Equals(keyname))
                                {
                                    if (oKey.Attributes["value"].Value.Trim().Length > 0)
                                    {
                                        keyvalue = oKey.Attributes["value"].Value;

                                        //Try to convert to integer32
                                        if (Globals.IsBoolean(keyvalue))
                                        {
                                            return (Convert.ToBoolean(keyvalue));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    oXml = null;
                }

                return defaultValue;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + "\nTypically an error here is from an improperly formatted config file. \nThe structure(XML) is compromised by a change you made.");
                return defaultValue;
            }
            finally
            {
                oXml = null;
                oList = null;
            }
        }

Same methods

ConfigUtil::GetConfigValue ( string keyname, double defaultValue ) : double
ConfigUtil::GetConfigValue ( string keyname, int defaultValue ) : int
ConfigUtil::GetConfigValue ( string keyname ) : string
ConfigUtil::GetConfigValue ( string keyname, string defaultValue ) : string