Retreive the country name in Windows Phone 7

You can get the country name in your Windows Phone 7 by using the System.Globalization assembly .

Generally the System locale is set in Windows Phone 7 via Settings -> System -> Region + language where one can select the system locale and other settings for windows phone 7 .

In this example i modified the system locale to English(India) from English(USA) .

The complete test English(India) can be retreived from the CultureInfo.CurrentCulture.EnglishName

public string CultureName()
{
     return CultureInfo.CurrentCulture.EnglishName;
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
     MessageBox.Show(CultureName());
}

 

Incase you need just the country name , you can use CurrentRegion.DisplayName or CurrentRegion.DisplayName  defined in the RegionInfo Class
.

public string GetCountryNameviaMethod1()
{
     return System.Globalization.RegionInfo.CurrentRegion.DisplayName;
}
public string GetCountryNameviaMethod2()
{
     return System.Globalization.RegionInfo.CurrentRegion.DisplayName;
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
     MessageBox.Show(GetCountryNameviaMethod1());
     MessageBox.Show(GetCountryNameviaMethod2());
}

It is also possible to retreive the Two letter ISO Region Name like US or IN via

TwoLetterISORegionName property defined in RegionInfo.CurrentRegion

public string GetTwoLetterISOName()
{
     return RegionInfo.CurrentRegion.TwoLetterISORegionName.ToUpper();
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
     MessageBox.Show(GetTwoLetterISOName());
}

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

No Responses

Leave a Reply


x

Interesting BlogPosts to read

Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...
Open Wordpad from command line in Windows
You can use the command "Write" from command line in Windows to open the WordPad application.D:\>...
Popular cross-platform (android and iOS) to-do list app
In this blog post, we will cover some of the popular to-do list app that is available on different p...