Create a list of Countries for SharePoint

Here is a method to create a list and populate the list with the countries of the world.

 

 

private void CreateCountryList()
       {
           SPContext.Current.Web.AllowUnsafeUpdates = true;
           SPWeb mySite = SPContext.Current.Web;
           SPListCollection lists = mySite.Lists;
           lists.Add(CountryList, "List of Countries", SPListTemplateType.GenericList);
 
           SPList countryList = mySite.Lists[CountryList];
 
           # region Countries
 
           //  This is a list of the United States and its Territories in alphabetical order: 
           String[] countryArray = {
                                   "United States"
                                   ,"Afghanistan"
                                   ,"Algeria"
                                   ,"Andorra" 
                                   ,"Angola"
                                   ,"Antigua and Barbuda" 
                                   ,"Argentina"
                                   ,"Armenia"
                                   ,"Australia"
                                   ,"Austria"
                                   ,"Azerbaijan"
                                   ,"Bahamas, The"
                                   ,"Bahrain"
                                   ,"Bangladesh"
                                   ,"Barbados"
                                   ,"Belarus" 
                                   ,"Belgium"
                                   ,"Belize" 
                                   ,"Benin"
                                   ,"Bhutan" 
                                   ,"Bolivia"
                                   ,"Bosnia and Herzegovina" 
                                   ,"Botswana"
                                   ,"Brazil" 
                                   ,"Brunei"
                                   ,"Bulgaria" 
                                   ,"Burkina Faso"
                                   ,"Burma"
                                   ,"Burundi"
                                   ,"Cambodia"
                                   ,"Cameroon"
                                   ,"Canada "
                                   ,"Cape Verde "
                                   ,"Central African Republic" 
                                   ,"Chad "
                                   ,"Chile "
                                   ,"China "
                                   ,"Colombia "
                                   ,"Comoros "
                                   ,"Congo (Brazzaville)" 
                                   ,"Congo (Kinshasa) "
                                   ,"Costa Rica "
                                   ,"Cote d'Ivoire "
                                   ,"Croatia "
                                   ,"Cuba "
                                   ,"Cyprus "
                                   ,"Czech Republic"
                                   ,"Denmark "
                                   ,"Djibouti "
                                   ,"Dominica "
                                   ,"Dominican Republic"
                                   ,"East Timor"
                                   ,"Ecuador "
                                   ,"Egypt "
                                   ,"El Salvador "
                                   ,"Equatorial Guinea "
                                   ,"Eritrea "
                                   ,"Estonia "
                                   ,"Ethiopia"
                                   ,"Fiji "
                                   ,"Finland"
                                   ,"France"
                                   ,"Gabon"
                                   ,"Gambia, The"
                                   ,"Georgia"
                                   ,"Germany"
                                   ,"Ghana"
                                   ,"Greece"
                                   ,"Grenada"
                                   ,"Guatemala"
                                   ,"Guinea"
                                   ,"Guinea-Bissau" 
                                   ,"Guyana"
                                   ,"Haiti"
                                   ,"Holy See"
                                   ,"Honduras"
                                   ,"Hong Kong"
                                   ,"Hungary"
                                   ,"Iceland"
                                   ,"India"
                                   ,"Indonesia"
                                   ,"Iran"
                                   ,"Iraq"
                                   ,"Ireland" 
                                   ,"Israel"
                                   ,"Italy"
                                   ,"Jamaica"
                                   ,"Japan"
                                   ,"Jordan"
                                   ,"Kazakhstan" 
                                   ,"Kenya "
                                   ,"Kiribati" 
                                   ,"Korea, North"
                                   ,"Korea, South"
                                   ,"Kosovo"
                                   ,"Kuwait"
                                   ,"Kyrgyzstan"
                                   ,"Laos" 
                                   ,"Latvia"
                                   ,"Lebanon" 
                                   ,"Lesotho"
                                   ,"Liberia" 
                                   ,"Libya"
                                   ,"Liechtenstein" 
                                   ,"Lithuania"
                                   ,"Luxembourg"
                                   ,"Macau"
                                   ,"Macedonia"
                                   ,"Madagascar"
                                   ,"Malawi"
                                   ,"Malaysia"
                                   ,"Maldives" 
                                   ,"Mali"
                                   ,"Malta"
                                   ,"Marshall Islands"
                                   ,"Mauritania"
                                   ,"Mauritius"
                                   ,"Mexico"
                                   ,"Micronesia"
                                   ,"Moldova" 
                                   ,"Monaco"
                                   ,"Mongolia" 
                                   ,"Montenegro"
                                   ,"Morocco" 
                                   ,"Mozambique"
                                   ,"Namibia" 
                                   ,"Nauru"
                                   ,"Nepal" 
                                   ,"Netherlands"
                                   ,"Netherlands Antilles"
                                   ,"New Zealand"
                                   ,"Nicaragua"
                                   ,"Niger"
                                   ,"Nigeria"
                                   ,"North Korea"
                                   ,"Norway"
                                   ,"Oman"
                                   ,"Pakistan"
                                   ,"Palau"
                                   ,"Palestinian Territories" 
                                   ,"Panama"
                                   ,"Papua New Guinea" 
                                   ,"Paraguay"
                                   ,"Peru" 
                                   ,"Philippines"
                                   ,"Poland" 
                                   ,"Portugal"
                                   ,"Qatar" 
                                   ,"Romania"
                                   ,"Russia" 
                                   ,"Rwanda"
                                   ,"Saint Kitts and Nevis" 
                                   ,"Saint Lucia"
                                   ,"Saint Vincent and the Grenadines" 
                                   ,"Samoa"
                                   ,"San Marino" 
                                   ,"Sao Tome and Principe"
                                   ,"Saudi Arabia" 
                                   ,"Senegal"
                                   ,"Serbia" 
                                   ,"Seychelles"
                                   ,"Sierra Leone" 
                                   ,"Singapore"
                                   ,"Slovakia" 
                                   ,"Slovenia"
                                   ,"Solomon Islands" 
                                   ,"Somalia"
                                   ,"South Africa" 
                                   ,"South Korea"
                                   ,"Spain" 
                                   ,"Sri Lanka"
                                   ,"Sudan" 
                                   ,"Suriname"
                                   ,"Swaziland" 
                                   ,"Sweden"
                                   ,"Switzerland" 
                                   ,"Syria"
                                   ,"Taiwan" 
                                   ,"Tajikistan"
                                   ,"Tanzania" 
                                   ,"Thailand"
                                   ,"Timor-Leste" 
                                   ,"Togo"
                                   ,"Tonga" 
                                   ,"Trinidad and Tobago"
                                   ,"Tunisia" 
                                   ,"Turkey"
                                   ,"Turkmenistan" 
                                   ,"Tuvalu"
                                   ,"Uganda"
                                   ,"Ukraine"
                                   ,"United Arab Emirates" 
                                   ,"United Kingdom"
                                   ,"Uruguay" 
                                   ,"Uzbekistan"
                                   ,"Vanuatu" 
                                   ,"Venezuela"
                                   ,"Vietnam"
                                   ,"Yemen"
                                   ,"Zambia" 
                                   ,"Zimbabwe"
                                  };
           # endregion
           # region Add items
           foreach (String country in countryArray)
           {
               SPListItem listItem = countryList.Items.Add();
               listItem["Title"] = country;
               listItem.Update();
           }
 
           # endregion

 
       }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

[tweetmeme only_single=”false”]
Advertisements

Got something to add?

Fill in your details below or click an icon to log in:

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