Office Communicator integration (Presence) in a custom webpart for SharePoint 2010

I recently spent a while trying to integrate the Office Communicator presence pawn into a custom web part and found it a little tricky so wanted to share my learning's. With SharePoint 2010's new social capabilities, I see this integration as being a must-have for any webpart or other custom interface that refers to people.

How does SharePoint do it?

Whenever a person's name is mentioned in the standard SharePoint UI, if the user has Office Communicator installed, the name will be shown with the Office Communicator 'pawn'. The pawn shows the user's status and gives them access to the pop-up menu to see more details.

Depending on which version of Office the user has installed, the experience will vary, however it will be the same experience as seen in Outlook. In Office 2010 it is a square icon with a richer drop-menu, in 2007 it is round.


In addition to the pawn, the user's name will be a hyperlink to their profile page. This will vary depending on whether the user is in the main 'User Profile Service Application' (or 'profile database' for old-school terminology) or not. If the user does have a profile then the hyperlink will redirect to the user's main profile page under My Site. If the user does not have a profile, the hyperlink will redirect to the SharePoint Foundation 'User Information' page. All users in a site have a 'User Information' page, if they also have a User Profile the settings from the profile are synchronised down to the User Information page on a scheduled basis (by a timer job).

The key piece of information to make the presence work is the user's SIP Address which is basically their IM address (This is not always the same as email address). When a users is either added to a site in SharePoint or has their profile imported, the SIP Address will be drawn from Active Directory which is where OCS stores it and placed into the SIP address field in either the user's profile which will in turn synchronise down to the site's local 'User Information' page.

How does the pawn work in terms of HTML?

The pawn is basically an IMG element which has "IMNRC('[user's SIP Address]')" for the onload function. This will user client-side script that is part of Office to load the presence pawn on the page.

The hyperlink on the user's name is just a simple A element which redirects to "/_layouts/userdisp.aspx?ID=[User's local user information list item ID]". This userdisp.aspx page will then redirect to the user's main profile page if they have a profile, otherwise it will display the basic information that the user information list item stores.

How to get the SIP Address?

Hopefully you'll have spotted by now that the presence pawn relies on the user's SIP Address. To get the SIP address you need to get the user's User Information list item from the local site's (SPWeb to be precise) SiteUserInfoList which is basically a hidden SPList that is in every web.

There is a handy property to get you to this list called 'SPWeb.SiteUserInfoList'. This will give you an SPList object which represents the User Information list. From here you just need to find the item that represents the user you wish to display. The best way to do this is via their ID (the ID of the list item) by calling SPWeb.SiteUserInfoList.GetItemById([int User's ID]), however you can also use a variety of other methods which use SPQuery or match a specific field to a value.

In most scenarios, you may be getting the user information from a SPFieldUserValueCollection which is basically the field type that is used for 'Person' fields. If this is the case you can use SPFieldUserValue.LookupId to get the ID of the user's User Information list item.

Putting it all together

This code sample is a method that accepts an SPFieldUserValueCollection and SPSite as inputs and returns back the HTML for displaying each entry in the SPFieldUserValueCollection with the presence pawn and link to their profile. This will be presented exactly as SharePoint presents it by default. This could be extended to use ALT tags in the IMG and A elements.

I then simply add the HTML to an HtmlWriter or in my case a TableCell.Text property to display it on screen.

I've take a few extra steps here by adding ID and alt tags and trying to make the code readable, but I'm sure you get the idea:

public string GetPresenceHTMLFromUVC(SPSite thisSite, SPFieldUserValueCollection uvc)
    StringBuilder html = new StringBuilder("");
    using (SPWeb thisWeb = thisSite.RootWeb)
        foreach (SPFieldUserValue uv in uvc)
            string sipAddress = "";
            //Get the sip address if it exists
            SPListItem user = thisWeb.SiteUserInfoList.GetItemById(uv.LookupId);
            if (user["SipAddress"] != null)
                sipAddress = user["SipAddress"].ToString();
            //construct the html for this user and add to overall html
            "<div id\"PresenceLink"
            , sipAddress
            , "\">"
            , "<img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('"
            , sipAddress
            , "')\" ShowOfflinePawn=\"1\" style=\"padding-right: 3px;\" id=\"PresencePawn"
            , sipAddress
            , "\" alt=\"presence pawn for "
            , sipAddress
            , "\"/>"
            , "<a href=\""
            , thisWeb.Url
            , "/_layouts/userdisp.aspx?ID="
            , uv.LookupId
            , "\" id=\"ProfileLink"
            , sipAddress
            , "\">"
            , uv.User.Name
            , "</a></div>"
    return html.ToString();

This article was published by


Martin Kearn
Senior Consultant
Microsoft Consulting Services UK

Click here for my bio page

Please feel free to contact me directly via email or via the blog comments if you have something to say about this article.

Comments (22)
  1. Martin,

    really nice reuse of the already existing functionality in Sharepoint 2010.



  2. Anoop says:

    This is just showing the unknown icon.. not displaying the gree icon in the wbpage.. can u pls assist..

  3. Anoop says:

    This is just showing the unknown icon.. not displaying the gree icon in the wbpage.. can u pls assist..

  4. ukpoint says:

    Please send your code and a screen shot to me and I';ll have a look

  5. Matt says:

    Great Post, do you have this packaged into a solution?

  6. Miguel says:

    What if you were trying to expose the OC pawn on a static .aspx page (not drawing from a webpart) for a particular contact person?

  7. Johannes says:

    My Problem is every time i edit the html source of a webpart and put in your code, sharepoint loses the "onload" part in the img tag, so its only the grey icon shown :/

    And another question: Is there a way in getting the online status of a user server side, so that a user doesnt need a running communicator ?

    Keep up the good work



  8. Jon says:

    There is no need to dispose of rootweb anymore (…/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx) . Just FYI.

  9. Ryan says:

    I am not a developer guy, so I am wondering where I put this code into. Please excuse my ignorance. Thanks

  10. Bhushan Gawale says:

    Nice Article Martin.. Thanks for Sharing ..

  11. Bryan Dougherty says:

    Interesting info.  I need to try this out.  I'm curious if you know the answers to any of these questions:

    – Do you have to have the Lync client installed for this like you do with the Silverlight controls?  

    – Any idea if this works with Office 365?  

    – Do you know if it will work on non-windows platforms?  


  12. Olafur Gislason says:

    This is a very nice approach but this gets very slow when displaying more than say 300 users on the same page like in a filtered phonebook scenario.  Do you have any ideas about that?

  13. Balaji says:

    If the Link icon is not showing please check the SIP address in the User Profile Properties

  14. Paul Beck says:

    Good explaination Martin, thanks for the explaination of how it fits together.  I have reference this post in my blog…/status-indicator-not-working.html

  15. Shiv says:

    Hi Martin,

    I am facing problem with OC indicator in custom sharepoint webpart. Can you assist me ?



  16. Suu30 says:

    This is a useful article.I want to implement it but as I am new to SharePoint Can you please tell me the steps to execute it i.e where exactly i need to write the code?



  17. Pruthvi says:


    does this approch work on chrome browsers as well, the default sharePoint page does not show presence in chrome browsers.



  18. Rahul says:

    I am not a programmer, but preparing a basic html page for my team. I want to show communicator status on html page. do we have any reference code for it

  19. Rohit says:


    I am new in share point development but I have created a web part to show the communicator on the page. I have referenced you code and my web-part only shows the users on the server.

    Can you please guide me how can I achieve the task?

    Here is a snap shot of my web part :…/webpart.jpg

    What am I missing?

    please reply ASAP.

  20. Rohit says:


    I have solved the previous problem but now I have a new one.. when I point on the chat icon on the pawn a message is shown 'to use this feature, log in to an instant messaging  program'.

    which messenger program it is talking about??

  21. Gagan says:


    The code above is not working on Chrome/Firefox. Is there any thing do we need to add/edit?

  22. Adarha says:

    the above code works upto getting the user, but I am able construct the html tag inside the c#.

    please give some inside on to this.

Comments are closed.

Skip to main content