jQuery : SharePoint Contact Card Web Part


I am back with another jQuery MagicJ. Whenever I was browsing through any social networking site I used to love those beautiful Contact List or Friends list. It was somewhere in the back of my mind to build something like this for our friend SharePoint. Today I got the opportunity to build some fancy (or not so fancy) contact card based on jQuery and SharePoint web services.

The best part of SharePoint is that gives you all the basic infrastructure for your day to day data requirements like Contact List, Task List, Calendar list and so on and once we have place to store such data jQuery gives you the power to read it and present it in the desired format.

Here also I tried something like that and came up with this solution for display contact list data in the card format.

Download the Code

Please download the source code and required files from : SudhirKe.jqContactCard.Source.zip in case the google docs link does not work you can download the code from my GitHub repository.



Default contact list from SharePoint. This solution also requires following files:-

– jQuery 1.4.3 [Note: jQuery1.5 is not compatible with SPServices yet.]

– jQuery UI 1.5.9

– jQuery SPServices

– jQuery UI Theme (I have used ui-lightness)

Apart from this I have developed following files:-

– jContactCard.css

– jContactCard.js

If you want to display the person image you can add a image field and get it link to your contact pictures. Other way is to read it from MySite, I have implemented a very basic solution and displayed the default image from SharePoint “/_layouts/images/no_pic.gif” with each contact.

See it in Action…

Here is the screen shot of the web part. Moving the mouse over a contact card highlights the contact card (thanks to jQuery UI J)

The Solution

I am really sorry for pasting the code as images, but it was getting formatted really badly by WordPress. Anyways I have given the link to download the code.

CSS File

CSS code is pretty simple, it just tells to format the contact card details and images etc.

jQuery Code

It’s very simple like my previous posts. I am using the SPServices solution from CodePlex to read data from SharePoint contact list. Very thanks to Marc D Anderson. Marc you have made huge differences to the life of jQuery and SharePoint and jQuery SharePoint lovers like us.

So the jQuery code is very oblivious, I am calling SharePoint lists web services using SPServices. I have called “processResult” method in the end to parse and format the return values. Below is the code to call the web service:-

Note: The below code can be found in the jContactCard.js file in the code.

My processResult method looks something like below:-


The required HTML script is really simple, the magical part is already taken care by jQuery all your html needs is a div element with “result” as id. Of course you need to add reference to the required JavaScript and CSS files.

Below is the HTML code.

Note: Please make sure to update the references of the JavaScript and CSS files when you upload it onto SharePoint document library.


– Upload all the JS and CSS file along with the HTML file onto SharePoint document library.

– Add a content editor web part and add link of the myjQuery.html file in the Content Link property.

– Below is the folder structure.

– JS folder contains required all the JavaScript files.

– CSS folder structure looks something similar to image below.

Hope this helps someone in need. Comments/Suggestions welcomed J


Adding “Recent Blog Post” web part programatically

This is a very basic post.  I really couldn’t find any post that could tell me how to add “Recent Blog Posts” web part using object modal.

The “Recent Blog Posts” web part is added by default on the SharePoint 2010 My Sites.  I was just wondering if we can add that using the SharePoint Object Modal.

I found out that adding a recent blog posts web part is really simple:-

// Get the web part collection
SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(“default.aspx”, PersonalizationScope.Shared);

Microsoft.SharePoint.Portal.WebControls.BlogView wpBlogView = new BlogView();
/*This Is very important.  Make sure To Link To the xsl file*/
wpBlogView.XslLink = “blog.xsl”;
wpBlogView.Title = “Recent Blog Posts”;

wpManager.AddWebPart(wpBlogView, “WebPartZone”, 0);

Hope this helps some one in need 🙂 



Pune User Group Meet – First Public Appearance

Saturday13th Dec 2008 was a superb day of my life,

I had taken my first session on Windows Sharepoint Services 3.0 with one of my best collegue Akhilesh Nirapure (akhilesh.nirapure@gmail.com).

It was my first public appearance on the Sharepoint. Giving me motivation for futher session.

I see that WSS 3.0/MOSS 2007 is still a jargon for most ot the people. The crowd was a good mix of people, starting with young studends (member of microsoft student partner) till IT Head of the company who were the decision makers.

It was a wonderful experience, I hope that it is the same for the audience. Apparently i had gone for Pune User Group meet for the first time (that too as a speaker).