Background
In one of my projects there is one module that requires a currency converter application. I am applying various techniques to convert the currency, such as storing the country name and related currency values in a database and retrieve them according to the related country but that is a very lengthy and complicated process.
Then after trying many options I decided to use a third party API to complete my requirement; I chose the Google API. So my intent is to write this article to help others that might me need to do the same type of task.
So let us start with the walkthrough.
Create the project as in:
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New Project" - "C#" - "Empty Project" (to avoid adding a master page).
- Give the Project name (such as LiveCurrencyconverter) or another as you wish and specify the location.
- Then right-click on Solution Explorer - "Add New Item" - "Default.aspx" page.
- Then right-click on Solution Explorer - "Add New Item" - "WebService.asmx" page.
- To see the "Default.aspx" source code please download the sample zip file.
Use the following code in WebService.asmx.cs of the WebService.asmx page:

In the preceding web services I have used one string named URL; on it I have saved a path of the Google API. Now add the service reference of the WebService.asmx web service to the Default.aspx page by right-clicking on the Solution Explorer, now run the application which looks such as in the following:

The above is the sample screen of an application, now provide the Input i9n above fields and click on "Convert" Button; the output will be as follows:

In the preceding Screen we can clearly seen that, I have converted 1 USD into Indian Rupees and the output is exactly the current market price, which is 54.58Rs.
Advantages
- Convert any country's currency using the current live market value.
- You have no need of a database to store the data.
- The free of cost API is provided by Google; there is not even a hidden cost.
Note
- For more code please download the sample zip file.
- Before using this article please read about the basics of Web Services, if you are unfamiliar with it.
Summary
I hope this article is useful for all readers, if you have any suggestion then please contact me, because of your suggestion others can get help from this article by improving it.


Aman KumarPosted Sep 30, 2020, 9:18 AM EDT
Where is WebService.asmx and WebService.asmx.cs code in the file. what a joke.
Vishal mahajanPosted May 14, 2019, 8:34 AM EDT
In download link Cs file is empty Please dont make a Joke
Annam SumanthPosted Oct 19, 2018, 8:50 AM EDT
Why this zip file is not downloading?
hirachand mudhalePosted May 16, 2016, 11:43 PM EDT
could you give me available free api ...
Vithal WadjeTOP 100Posted Feb 28, 2016, 6:38 PM EST
Thanks .. please check latest API
Salman KavishPosted Feb 27, 2016, 8:37 AM EST
Nice article.
Salman KavishPosted Feb 27, 2016, 8:37 AM EST
public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency) { string Output = ""; const string fromCurrency1 = "USD"; const string toCurrency1 = "INR"; const double amount1 = 2000; // For other currency symbols see http://finance.yahoo.com/currency-converter/ // Construct URL to query the Yahoo! Finance API const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1"; string url = string.Format(urlPattern, fromCurrency1, toCurrency1); // Get response as string string response = new WebClient().DownloadString(url); // Convert string to number double exchangeRate = double.Parse(response, System.Globalization.CultureInfo.InvariantCulture); // Output the result Output=(amount1*exchangeRate).ToString(); return Output; // http://salmankavish.blogspot.in/2016/02/currency-converter-using-c.html }
Salman KavishPosted Feb 27, 2016, 8:37 AM EST
i have use yahoo finance api. one can take ref from following code.
Mark OngPosted Aug 10, 2015, 12:28 AM EDT
I have encounter errors regarding "the type or namespace name could not be found". Any Solutions for that ?
ajay kumarPosted Aug 9, 2015, 9:26 PM EDT
This article seems outdated now, http://www.google.com/ig/calculator api is no longer up and running
Rajagopalan R VPosted Apr 22, 2015, 4:45 AM EDT
Hi Mr. Vithal Wadje the following link in this Application Jquery/JScript.js Code Page (Link Consists Page) http://www.geoplugin.net/currency_converter.gp?jsoncallback=? is throwing " ERR01 "
Vithal WadjeTOP 100Posted Dec 29, 2014, 4:57 PM EST
need to be install valid https certificate
hemant sharmaPosted Dec 26, 2014, 4:00 AM EST
Its not working on https
Vithal WadjeTOP 100Posted Jun 4, 2014, 9:32 AM EDT
download above zip file
Sumit TesterPosted Jun 3, 2014, 11:58 AM EDT
Please send me the updated code. My email id is: [email protected]
sameer albalushiPosted May 12, 2014, 11:04 AM EDT
please send me the updated code my id is [email protected]
Sehrish AliPosted Mar 28, 2014, 5:55 AM EDT
please send me updated code too my id is [email protected]
Vithal WadjeTOP 100Posted Feb 25, 2014, 7:28 AM EST
shaukeen khan sir send mi your sample code
shaukeen khanPosted Feb 25, 2014, 1:07 AM EST
dear code run but i am not getting any result ? please help
ketan italiyaPosted Nov 21, 2013, 10:17 PM EST
Sir,Everything is work but option in dropdown for select indian ruppes into dollar etc. is not shown is that google api related problems
ketan italiyaPosted Nov 21, 2013, 9:16 PM EST
thankss.sir
Vithal WadjeTOP 100Posted Nov 21, 2013, 8:19 AM EST
download updated
pappu singhPosted Nov 21, 2013, 1:31 AM EST
LiveCurrencyConverter.zip not working
Vithal WadjeTOP 100Posted Nov 16, 2013, 8:24 AM EST
thanks sir check your email,same i will be update here
althaf22Posted Nov 16, 2013, 3:44 AM EST
Hi vithal.Jee , Code is giving run time error in Regular expression line, C#, plz send me the updated one plz. to [email protected]
Vithal WadjeTOP 100Posted Nov 8, 2013, 8:19 AM EST
thanks Geetha Mdm, message me your email Id on C# corner, i will send you latest solution
Geetha LaksmiPosted Nov 7, 2013, 5:44 PM EST
hi,the code is working but it found an error at the regex part....can you help me with this
Hitesh GuptaPosted Oct 18, 2013, 4:29 AM EDT
When I am using regularly, It stop working due to captcha..
dinesh kumarPosted Oct 12, 2013, 5:22 PM EDT
helpfull for me ;;but i want to be get this updated currency in database plz give me code for this
Vithal WadjeTOP 100Posted Mar 26, 2013, 2:02 AM EDT
chill sir,make some changes according to your VS and then run
chill applePosted Feb 2, 2013, 10:37 PM EST
it is showing assembly error
Vithal WadjeTOP 100Posted Jan 10, 2013, 11:08 PM EST
thanx sir
duc nguyeneditedPosted Jan 10, 2013, 9:54 PM ESTEdited Feb 3, 2013, 6:05 PM EST
Thank you! this is helpful for me