This is a clock web part shows digital clocks depends on the user needs. Thanks to anujpant for sharing this at codeplex. You can find the original source and wsp file here.
The original clock looks like this
Customized clock will looks like this
You can download the customized source code here what I edited for my requirement.
I customized this with VS 2008. Here I wanted to display the city/country name beside the clock rather than displaying under the clock. So I added a new cell into the same row.
Then I wanted to remove clock skins. The original clock can select 4 color skins as the user wants. After deploying the clock I realized that displaying seconds is disturbing the users. It’s worse when you added more than 5 clocks. So without removing the seconds I hid it.
Recently one of our customers wanted a currency converter on their SharePoint site. This can be done developing a custom web part. I developed a web part using VS 2008. So I thought of publishing it with the source then anyone can download and modify it as they want.
Here is what it looks like
You can download the source codes here.
First I want to thank Shalvin for the free currency converter web service. Here he has explained how we can use the web service in SharePoint. Now I am going to explain my web part with some screenshots.
Now open your VS2008 and create a new project using Web Part template.

We start adding the web service to our project. Right click you project in the solution explorer and click on Add Web Reference. Type our web service URL in the URL box and click Go. If you want you can change the Web Reference Name and click Add Reference.
Open your .cs file and define some variables and controls.
CurrencyConvertor.CurrencyConvertor cc = new CurrencyConvertor.CurrencyConvertor();
double dblConv;
double dblAmt;
DropDownList lstEndCurr;
DropDownList lstStartCurr;
Button btnSend;
Label lblConversion;
TextBox txtAmount;
Label lblConvert;
Label lblInto;
Label lblAmount;
Label lblDetails;
Make sure you have “WebControls” namespace in your class
using System.Web.UI.WebControls;
We are going to have two DropDownList controls for “From” and “To” fields. So we need to fill them with currency codes with description. So here I have wrote a function for that which will return a HashTable and you can directly bind that to the DropDownList. Here if you want you can directly call method from the web service and fill the DropDoenList.
private Hashtable setDDL()
{
Hashtable hTable = new Hashtable();
hTable.Add("AFA", "AFA-Afghanistan Afghani");
hTable.Add("ALL", "ALL-Albanian Lek");
hTable.Add("DZD", "DZD-Algerian Dinar");
return hTable;
}
Then we need to add our controls to a collection. So we can call them when we render the page. So here we use enumeration type.
private enum WebPartControls
{
lblAmount,
txtAmount,
lblConvert,
lstStartCurr,
lblInto,
lstEndCurr,
btnSend,
lblConversion,
lblDetails
}
Now you can add code for all your controls to the “CreateChildControls” method. Here I haven’t add all my codes in this post.
protected override void CreateChildControls()
{
//Set properties for Amount label
lblAmount = new Label();
lblAmount.Text = "Amount :";
lblAmount.Width = 60;
this.Controls.Add(lblAmount);
//Set properties for Amount textbox
txtAmount = new TextBox();
txtAmount.Width = 100;
this.Controls.Add(txtAmount);
//Set properties and items for from DropDownList
lstStartCurr = new DropDownList();
//Define a Hashtable and set the return Hashtable from setDDL function
Hashtable hTableStart = new Hashtable();
hTableStart = setDDL();
lstStartCurr = new DropDownList();
lstStartCurr.DataSource = hTableStart;
lstStartCurr.DataTextField = "Value";
lstStartCurr.DataValueField = "Key";
lstStartCurr.DataBind();
this.Controls.Add(lstStartCurr);
//Set properties and event for convert button
btnSend = new Button();
btnSend.Click += new EventHandler(btnSend_Click);
btnSend.Text = "Convert";
btnSend.Width = 75;
this.Controls.Add(btnSend);
ChildControlsCreated = true;
}
Next we can start writing the event for our convert button
void btnSend_Click(object sender, EventArgs e)
{
//Creat two object from the currency web service
CurrencyConvertor.Currency fromCurrency = new CurrencyConvertor.Currency();
CurrencyConvertor.Currency toCurrency = new CurrencyConvertor.Currency();
//Convert selected items from DropDownLists into currency objects
fromCurrency = (CurrencyConvertor.Currency)Enum.Parse(typeof(CurrencyConvertor.Currency),
this.lstStartCurr.SelectedValue.ToString());
toCurrency = (CurrencyConvertor.Currency)Enum.Parse(typeof(CurrencyConvertor.Currency),
this.lstEndCurr.SelectedValue.ToString());
//Pass our from and to currency codes to web service and get the return value to a variable
dblConv = cc.ConversionRate(fromCurrency, toCurrency);
lblConversion = new Label();
dblAmt = Double.Parse(txtAmount.Text.ToString()) * dblConv;
lblConversion.Text = dblAmt.ToString();
this.Controls.Add(lblConversion);
//Set the value for Details label with the return values
lblDetails = new Label();
lblDetails.Text = "1.00 " + lstStartCurr.SelectedValue.ToString() + " = " + dblConv.ToString()
+ " " + lstEndCurr.SelectedValue.ToString();
lblDetails.Style["text-align"] = "center";
this.Controls.Add(lblDetails);
}
Next we can start out render method. This is the method which will create UI in our web part. We can insert html break tags between controls to have space in-between.
protected override void Render(HtmlTextWriter writer)
{
try
{
Controls[(int)WebPartControls.lblAmount].RenderControl(writer);
Controls[(int)WebPartControls.txtAmount].RenderControl(writer);
writer.Write("<BR>");
writer.Write("<BR>");
if (Controls.Count == 9)
{
Controls[(int)WebPartControls.lblDetails].RenderControl(writer);
}
}
catch(Exception ex)
{
}
Now we are done all coding things. Select your project and go to properties. It will open the project property window. Click on Debug and click on Start browser with URL. Type your site URL in the text box.
Now go to Build menu and select Deploy Solution. Visual studio will create our web part and deploy it into the SharePoint site.
Happy coding!
Recently I did a session at ITPro forum about Business Data Catalog with SharePoint 2007. Here I wanted to focus all our techies that how we are able to connect LOB systems to SharePoint 2007 using BDC and no coding solutions with LOB systems on SharePoint 2007.
Below the agenda of my session.
- Introduction to Business Data Catalog
- Why you need BDC?
- Live Demo with Simple BDC Application
Screenshot of simple BDC application
- Live Demo on Configuring Search with BDC Application
Screenshot of search results
- Live Demo on Configuring InfoPath from with BDC Application
Screenshot of Selected record value passed to a from
Those who are couldn’t attend to this session can download the files here.
Some memories from the session

Date : 26th August 2009
Time : 6 PM onwards
Venue : Microsoft Sri Lanka Auditorium