Adding World Clock, and Exchange Rates Web Parts to #SharePoint

One of the most required accessories web parts to SharePoint portals is “World Clock web part” and ” Exchange Rates web part”, today I’m going to show you how to implement both with your SharePoint environment.

  • Adding World Clock:

First, you should know that there are dozens of free or purchased versions of this web part, but why to purchase when you can make one J

SharePoint Object Model provide us with a class library for Regional Settings which include local and global time zones, you can find it within ” Microsoft.SharePoint.dll under the class property  ” SPRegionalSettings.GlobalTimeZones “:

  • Create a new Visual Web part
  • Add a Grid View control to the web part, and name it: grdWorldClock
  • In the .CS file for the visual web part add the “Microsoft.SharePoint” name space
  • In the page load section add the following code:

    protected
    void Page_Load(object sender, EventArgs e)

    {

    SPTimeZoneCollection timeZoneColl = SPRegionalSettings.GlobalTimeZones;

    // Creating table 

    DataTable dt = new
    DataTable();

    // Adding Columns

    dt.Columns.Add(“Description”);

    dt.Columns.Add(“Time Zone”);

    foreach (SPTimeZone tz in timeZoneColl)

    {

    DateTime currentLocalDateTime = DateTime.Now;

    DateTime currentDestDateTime = tz.UTCToLocalTime(currentLocalDateTime.ToUniversalTime());

    // Adding Rows

    DataRow dr;

    dr = dt.NewRow();

    dr[“Description”] = tz.Description.ToString();

    dr[“Time Zone”] = currentDestDateTime.ToString();

    dt.Rows.Add(dr);

    }

    // Connecting Data Source to our GridView

    grdWorldClock.DataSource = dt;

    grdWorldClock.DataBind();

    dt.Dispose();

    }

  • Just deploy your solution to your farm and you will see the results like below:

With some UI tweaks you can enhance the interface and make it better view, also you can make it as a dropdown list and the results changes upon click.

Also there is a fast solution using a ready made code from the well know site “Clock Link”, and here you are the link to code:

http://www.clocklink.com/gallery/view/world001

You can add it within your Embedded Code area:

Then insert the following code:

Then the result will be like that:

Enjoy J.

 

  • Now how to add an Exchange Rates web part.

It’s very simple, just go to The Money Converter web site http://themoneyconverter.com and from the upper side select Exchange Rates, then from the table there select your currency preference, I have picked up SAR, http://themoneyconverter.com/SAR/Exchange_Rates_For_Saudi_Riyal.aspx

Then from the left side select RSS feeds which is automatically generated for SAR, http://themoneyconverter.com/rss-feed/SAR/rss.xml.

Now add an RSS Viewer web part to your desired page:

Then in the property menu add the RSS link like below:

Then after adding it the web part will load the exchange rate data for your selected currency like below:

 

You can also enhance the preview by tweaking UI.

Advertisements

About Hossam Kamal

Hossam Kamal Senior SharePoint Developer with high development skills in C#, ASP.NET, SharePoint Server Technologies, jQuery, CSS, XML, O.O.D, SSRS and MS.SQL Server.
This entry was posted in SharePoint General. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s