How to get country list from windows OS

The code below comes from this link, http://msforums.ph/forums/p/53854/269887.aspx
You can get it from the registry (if you’re not using windows 7)
Private Sub GetCountryListFromRegistry(ByVal cbo As ComboBox)
        Dim countryList As RegistryKey = Registry.LocalMachine.OpenSubKey(“Software\Microsoft\Windows\CurrentVersion\Telephony\Country List”)
        If countryList IsNot Nothing Then
            Try
                cbo.Items.Clear()             
                Dim countryListSubkeys As String() = countryList.GetSubKeyNames()
                For Each countryCode As String In countryListSubkeys
                    Dim country As RegistryKey = countryList.OpenSubKey(countryCode)
                    Dim countryName As String = country.GetValue(“Name”).ToString()
                    cbo.Items.Add(countryName)
                    country.Close()
                Next
              countryList.Close()
            Catch ex As Exception
            End Try
        End If
    End Sub

 For windows 7, you can use the CultureInfo class
        For Each cultureInfo As CultureInfo In CultureInfo.GetCultures(CultureTypes.FrameworkCultures)
            Dim regionInfo As RegionInfo
            Try
                regionInfo = New RegionInfo(cultureInfo.Name)
            Catch
                Continue For
            End Try
            Dim kvp As New KeyValuePair(Of String, String)(regionInfo.EnglishName, regionInfo.ThreeLetterISORegionName)
            If Not countryList.ContainsKey(regionInfo.EnglishName) Then
                countryList.Add(kvp.Key, kvp.Value)
                ListBox1.Items.Add(regionInfo.EnglishName)
            End If
        Next
        ListBox1.Sorted = True

Here are the other references:
http://devpinoy.org/blogs/cvega/archive/2006/06/02/3300.aspx
http://helios.ca/2009/05/30/aspnet-mvc-cascading-dropdownlist-with-jquery/
http://www.dotnetspider.com/resources/28774-Adding-Country-Name-DropDwonList.aspx
http://aghausman.net/dotnet/Get-Countries-Name-in-Net.html
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/dd3f2293-0b0a-4bed-9812-83a39111c0a8

Advertisements
This entry was posted in VB.NET 2 AND ASP.NET 2. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s