To read web.config, and find any section there are number of solutions available, one such method to access globalization section which is under system.web of web.config is as follows:
In web.config i have
<globalization uiCulture="nl-NL" />
Now to read the uiculture in codebehind file in asp.net
string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig("system.web/globalization"))).UICulture;
Lets say for example i have to display date according to culture set in web.confg so:
public object GetDateCulture(object date)
{
string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig("system.web/globalization"))).UICulture;
System.IFormatProvider format = new System.Globalization.CultureInfo(uicul, true);
date = Convert.ToDateTime(date).ToString("dd MMM yyyy", format);
return date;
}
Ouput will be:
if culture is english : 22 May 2009
if culture is dutch : 22 Mai 2009
0 comments:
Post a Comment