Click here to Skip to main content
15,943,729 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi I'm new to dotnet platform...I want to know the code for currency exchange rate in any one help me?

What I have tried:

This is my code

ASP.Net code

        <asp:Label ID="lbl_Amount" runat="server" Text="Amount"></asp:Label></td>
            <asp:TextBox ID="txt_amount" runat="server"></asp:TextBox>
                <asp:Label ID="lbl_FromCurrency" runat="server" Text="From Currency"></asp:Label> </td>
                    <asp:TextBox ID="txt_fromCurrency" runat="server"></asp:TextBox>
                        <asp:Label ID="lbl_toCurrency" runat="server" Text="To Currency"></asp:Label></td>
                       <asp:TextBox ID="txt_ToCurrency" runat="server"></asp:TextBox></td> </tr>
                           <asp:Label ID="lbl_value" runat="server" Text=""></asp:Label></td>
                           <asp:Button ID="Btn_Convert" runat="server" Text="Convert"  OnClick="CurrencyConversion"/></td></tr></table>

C# Code

public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency)
           WebClient web = new WebClient();
           string url = string.Format("{0}&to={1}&a={2}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
           string response = web.DownloadString(url);
           Regex regex = new Regex("<span class=bld>(.*?)</span>");

           var result = regex.Match(response).Groups[1].Value;
           return result;
Updated 11-Jul-17 3:22am

The EuropeanCentralBank has some possibilyties.
Euro foreign exchange reference rates[^]

public static DataTable GetCurrencyListFromWeb1()
           DataTable returnList = new DataTable();
           returnList.Columns.Add("currency", typeof(string));
           returnList.Columns.Add("rate", typeof(decimal));
           Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
           string date = string.Empty;
           using (XmlReader xmlr = XmlReader.Create(@""))
               while (xmlr.Read())
                   if (xmlr.NodeType != XmlNodeType.Element) continue;
                   if (xmlr.GetAttribute("time") != null)
                       date = xmlr.GetAttribute("time");
                   else returnList.Rows.Add(xmlr.GetAttribute("currency"), decimal.Parse(xmlr.GetAttribute("rate"), CultureInfo.CurrentCulture));
           returnList.Rows.Add("EUR", 1);
           return returnList;
Share this answer
Member 13273157 4-Nov-19 0:57am    
It works... But is it possible based on particular Currency

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900