I want to download a website's content based on user's current region. For that I need country code like US , FR etc.. How to get that?
I tried these:
this always shows US. I think it comes from app manifest.
var region = RegionInfo.CurrentRegion;
and this:
var cultureName = new DateTimeFormatter("longdate", new[] { "US" }).ResolvedLanguage;
return new CultureInfo(cultureName);
this works. returns something like en-US which I can extract country code from it. but sometimes it may return only language en without country code.
How to get system's current two character country code? thanks.
To get user's home region setting, we can use GlobalizationPreferences.HomeGeographicRegion property.
// Obtain the user's home geographic region.
var region = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;
The home region is usually set when Windows is installed and is available in
Settings → Time & language → Region & language → Country or region.
Windows.Globalization also has a GeographicRegion object that is provided as a helper object. It lets apps inspect details about a particular region, such as its display name, native name, and currencies in use.
// Get the user's geographic region and its two-letter identifier for this region.
var geographicRegion = new Windows.Globalization.GeographicRegion();
var code = geographicRegion.CodeTwoLetter;
For more info, please see Manage language and region.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With