C Sharp - Useful Code [GetCountryNames]

Posted by Deepak under C# category on | Views : 2817
Most of the web applications and windows applications some time needs the country list to be displayed to the user.

Here is the class....use them and try to share it if possible..

public class GetCountryNames

public List<string> GetCountryList()
List<string> countryList=new List<string>();
string keyPath = @"SOFTWARE\Microsoft\Windows\Currentversion\Telephony\Country List\";
string[] allData = Registry.LocalMachine.OpenSubKey(keyPath).GetSubKeyNames();
foreach (string s in allData)
//International Freephone Service
if (Registry.LocalMachine.OpenSubKey(keyPath + s).GetValue("Name").ToString() != "International Freephone Service")
countryList.Add(Registry.LocalMachine.OpenSubKey(keyPath + s).GetValue("Name").ToString());
return countryList;

Comments or Responses

Posted by: Poster on: 2/5/2009 Level:Starter | Status: [Member]
I copied and pasted the code, I just faced a bit problem in finding the namespace for "Registry.LocalMachine", I included "using Microsoft.Win32;" and it worked so well.

I must say its Awesome!!! I had never imagined such an easy way to list the name of the countries.

Thanks Deepak.
Posted by: Deepak on: 2/5/2009 Level:Starter | Status: [Member]


I am trying to get the all the TimeZones....!!

This is one nore useful code for all develoeprs.

I will post it soon..

If you can post this...its good and worth..

Login to post response