Using System;
Using System. Web;
Using System. Collections. Generic;
Using System. Configuration;
Using System. Linq;
Using System. Xml;
Namespace CommHelper
{
Public class AppConfig
{
/// <Summary>
/// Obtain the bool value of the Configuration Attribute
/// </Summary>
/// <Param name = "key"> </param>
/// <Returns> [True/False] </returns>
Public static bool GetBool (string key)
{
Bool isBool = false;
Try
{
IsBool = Convert. ToBoolean (ConfigurationManager. deleetask[ key]);
}
Catch {
}
Return isBool;
}
/// <Summary>
/// Obtain the Int value of the Configuration Attribute
/// </Summary>
/// <Param name = "key"> </param>
/// <Returns> </returns>
Public static int GetInt (string key)
{
Int iValue =-1;
Try
{
IValue = Convert. ToInt32 (ConfigurationManager. etettings [key]);
}
Catch {}
Return iValue;
}
/// <Summary>
/// Obtain the string value of the Configuration Attribute
/// </Summary>
/// <Param name = "key"> </param>
/// <Returns> </returns>
Public static string GetString (string key)
{
Return Convert. ToString (ConfigurationManager. deleetask[ key]);
}
/// <Summary>
/// Obtain the Int value of the Configuration Attribute
/// </Summary>
/// <Param name = "key"> </param>
/// <Param name = "name"> </param>
/// <Returns> </returns>
Public static int GetInt (string key, string name)
{
String str = GetString (key, name );
If (str! = Null)
{
Return Convert. ToInt32 (str );
}
Return-99999;
}
/// <Summary>
/// Obtain the string value of the Configuration Attribute
/// </Summary>
/// <Param name = "key"> </param>
/// <Param name = "name"> </param>
/// <Returns> </returns>
Public static string GetString (string key, string name)
{
XmlDocument document = new XmlDocument ();
Document. Load (HttpContext. Current. Server. MapPath ("/web. config "));
XmlElement element = (XmlElement) document. SelectSingleNode (string. Format ("/configuration/extendSettings/add [@ key = '{0}']", key ));
If (element! = Null)
{
Return element. GetAttribute (name );
}
Return null;
}
[Obsolete ("This method is obsolete, it has been replaced by GetString method.", true)]
Public static string ReadAppSetting (string key)
{
Return ConfigurationManager. deleetask[ key];
}
}
}