IP2Currency: Microsoft ASP.Net - C# Sample Code

The sample code below provide you an example on how to obtain the latest currency exchange rate and the homeland currency by visitor's IP address.


//////////////////////////////////////////////////////////////////////////////////
//
//  This source code is only licensed to our premium subscribers. It is provided "as is" and without warranties.
//
//  http://www.fraudlabs.com © All Rights Reserved 2012
///
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using IP2CurrencyWebServiceClientCSharp.IP2CurrencyWebService;

namespace IP2CurrencyWebServiceSoapClient
{
	/// <summary>
	/// Summary description for IP2CurrencyWebServiceClientCSharp.
	/// </summary>
	public class IP2CurrencyWebServiceClientCSharp : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtVisitorIP;
		protected System.Web.UI.WebControls.TextBox txtFromCurrencyCode;
		protected System.Web.UI.WebControls.TextBox txtToCurrencyCode;
		protected System.Web.UI.WebControls.TextBox txtFromAmount;
		protected System.Web.UI.WebControls.TextBox txtLicense;
		protected System.Web.UI.WebControls.TextBox txtResult;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Button btnClear;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
			this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void IP2CurrencyWebService()
		{
			IP2CurrencyWebService x_IP2Currency = new IP2CurrencyWebService();
			IP2CurrencyOutput oIP2Currency = new IP2CurrencyOutput();
			IP2CurrencyInput iIP2Currency = new IP2CurrencyInput();

			try
			{
				iIP2Currency.VISITORIP = this.txtVisitorIP.Text;
				iIP2Currency.FROMCURRENCYCODE = this.txtFromCurrencyCode.Text;
				iIP2Currency.TOCURRENCYCODE = this.txtToCurrencyCode.Text;
				iIP2Currency.FROMAMOUNT = this.txtFromAmount.Text;
				iIP2Currency.VISITORIP = this.txtVisitorIP.Text;
				iIP2Currency.LICENSE = this.txtLicense.Text;

				oIP2Currency = x_IP2Currency.IP2Currency(iIP2Currency);

				this.txtResult.Text = "FROMCURRENCYCODE:" + oIP2Currency.FROMCURRENCYCODE + "\n";
				this.txtResult.Text += "TOCURRENCYCODE:" + oIP2Currency.TOCURRENCYCODE + "\n";
				this.txtResult.Text += "TOCURRENCYSYMBOL:" + oIP2Currency.TOCURRENCYSYMBOL + "\n";
				this.txtResult.Text += "FROMAMOUNT:" + oIP2Currency.FROMAMOUNT + "\n";
				this.txtResult.Text += "TOAMOUNT:" + oIP2Currency.TOAMOUNT + "\n";
				this.txtResult.Text += "CONVERSIONRATE:" + oIP2Currency.CONVERSIONRATE + "\n";
				this.txtResult.Text += "TOCOUNTRYNAME:" + oIP2Currency.TOCOUNTRYNAME + "\n";
				this.txtResult.Text += "TOCOUNTRYCODE:" + oIP2Currency.TOCOUNTRYCODE + "\n";
				this.txtResult.Text += "CREDITSAVAILABLE:" + oIP2Currency.CREDITSAVAILABLE + "\n";
				this.txtResult.Text += "MESSAGE:" + oIP2Currency.MESSAGE + "\n";
			}
			catch (Exception ex)
			{
				Response.Write(ex.Message);
			}
		}		
		private void ClearScreen()
		{
			this.txtVisitorIP.Text = "";
			this.txtFromCurrencyCode.Text = "";
			this.txtToCurrencyCode.Text = "";
			this.txtFromAmount.Text = "";
			this.txtVisitorIP.Text = "";
			this.txtLicense.Text = "";
			this.txtResult.Text = "";
		}

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{
			this.IP2CurrencyWebService();
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			this.ClearScreen();
		}
	}
}

Download the source code
You need a license key for the solution. And, it is free and available at IP2Currency Free License