Friday, October 1, 2010

Read AppSettings and-or XML File

public static string GetCustomConfigValue(string filePath, string keyName)
{
string retVal = "";
XmlDocument doc = new XmlDocument();
try
{
doc.Load(HttpContext.Current.Server.MapPath(filePath));
XmlNode root = doc.DocumentElement;
retVal = root.SelectSingleNode(keyName).ChildNodes[0].Value;
}
catch (Exception ex)
{
logAll("DSS Web 2 Beta", ex.ToString(), utilFns.Common.GetCurrentPageName(), "XML error in utilFns.cs: " + filePath + " : " + keyName, true);
}
return retVal;
}

public static string GetAppConfigValue(string KeyName)
{
return ConfigurationSettings.AppSettings[KeyName];
}

No comments: