Thomas Thomas - 22 days ago 11
C# Question

Best way to get the international country ISD phone codes

I am looking for any routine which will give me the ISD code for any country. I searched Google a lot but found nothing similar. I tried to do it in this way:

public string ISDCode(string strCountryCode)
{
string countryCode = "";
XmlDocument xdoc = new XmlDocument();
string url = "http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/CountryIntPhoneCode?";
url = url + "sCountryISOCode=" + strCountryCode;
xdoc.Load(url);
countryCode = xdoc.DocumentElement.InnerText.ToString();
return countryCode;
}


I use this web service

but often it is not accessible. Please guide me how I can get the ISD code for any country. I will just pass country code only. For example I will pass 'CA' for Canada and the routine will give me the Canada ISO code. Please help. thanks.

Answer

If you don't want to use a webservice for some reason, I'd go to Wikipedia:

http://en.wikipedia.org/wiki/List_of_country_calling_codes

...or here:

http://countrycode.org/

...and build my own lookup table from that. In fact writing a script to generate that automatically sounds kind of fun to me. :)