You can use any of this following API's :-
free.currencyconverterapi.com
currencylayer.com
currency-api
Read currency rate details available from Web
Peter_1985
2,506
Reputation points
Hi,
Is there any App/service to get the current currency rate details, from the web, and to flush data into VS project?
3 answers
Sort by: Most helpful
-
AddWebSolution 161 Reputation points
2021-06-25T05:17:41.893+00:00 -
Castorix31 81,736 Reputation points
2021-06-25T05:57:08.727+00:00 You can use WebRequest
Quick test in C# =>
WebRequest request = WebRequest.Create("http://www.floatrates.com/daily/usd.json"); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); string sRateBegin = "\"rate\":"; string sRateEnd = ","; string sRate = responseFromServer.Substring(responseFromServer.IndexOf(sRateBegin) + sRateBegin.Length); sRate = sRate.Substring(0, sRate.IndexOf(sRateEnd)); Console.WriteLine("1 USD = {0} EUR", sRate); reader.Close(); response.Close();
I get :
1 USD = 0.83791020896443 EUR
-
Karen Payne MVP 35,036 Reputation points
2021-06-25T12:14:26.587+00:00 See if this works for you, code sample done in VS2019.
Imports System.Xml Partial Public Class Form1 Inherits Form Private ReadOnly ExchangeRateToEuro As Dictionary(Of String, Decimal) = New Dictionary(Of String, Decimal)() Public Sub New() InitializeComponent() End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try LoadRates() FromCurrency.SelectedIndex = 0 ToCurrency.SelectedIndex = 0 Catch ex As Exception ConvertButton.Enabled = False MessageBox.Show(ex.Message) End Try End Sub Private Sub LoadRates() Dim xmlDoc As New XmlDocument() xmlDoc.Load("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml") UpdateLabel.Text = $"Rates Updated: {xmlDoc.DocumentElement.ChildNodes(2).ChildNodes(0).Attributes("time").Value}" For Each node As XmlNode In xmlDoc.DocumentElement.ChildNodes(2).ChildNodes(0).ChildNodes ExchangeRateToEuro.Add(node.Attributes("currency").Value, Decimal.Parse(node.Attributes("rate").Value)) FromCurrency.Items.Add(node.Attributes("currency").Value) ToCurrency.Items.Add(node.Attributes("currency").Value) Next End Sub Private Sub ConvertButton_Click(sender As Object, e As EventArgs) Handles ConvertButton.Click If Not ConvertButton.IsHandleCreated Then Return Dim conversionNum As Decimal = (amount.Value / ExchangeRateToEuro(FromCurrency.Text)) * ExchangeRateToEuro(ToCurrency.Text) ConvertValue.Text = amount.Value & " " & FromCurrency.Text & " = " & conversionNum.ToString("0.00") & " " & ToCurrency.Text End Sub Private Sub amountLeave(sender As Object, e As EventArgs) Handles amount.Leave If Not amount.IsHandleCreated Then Return If amount.Text = String.Empty Then amount.Value = amount.Minimum amount.Text = amount.Value.ToString() End If End Sub End Class