My customer asked for a contact details webpart with the feature if the contact is available on Lync or not. It isn’t difficult to get the contact details from a user profile in contrast to get the lync presence. I spend a few hours to get how it works in SharePoint 2010 and finally I found this blog post of Martin Kearn. With a little bit of fine tuning I rewrote the function to let it work with the UserProfile property instead of a SPFieldUserValueCollection.
The code that do the thing:
Code Snippet
- public static string GetPresenceHTMLFromUserProfile(UserProfile profile)
- {
- StringBuilder html = new StringBuilder("");
- string sipAddress = "";
- //Get the sip address if it exists
- if (profile[PropertyConstants.WorkEmail].Value != null)
- {
- sipAddress = profile[PropertyConstants.WorkEmail].Value.ToString();
- }
- //construct the html for this user and add to overall html
- html.Append(String.Concat(
- "<span><a href=\""
- , Helper.GetUserProfileUrl(profile)
- , "\" id=\"ProfileLink"
- , sipAddress
- , "\">"
- , profile.DisplayName
- , "</a>"
- , "<img border=\"0\" height=\"12\" src=\"/_layouts/images/imnhdr.gif\" onload=\"IMNRC('"
- , sipAddress
- , "')\" ShowOfflinePawn=\"1\" style=\"padding-left: 5px;\" id=\"PresencePawn"
- , sipAddress
- , "\" alt=\"presence pawn for "
- , sipAddress
- , "\"/></span>"
- ));
- return html.ToString();
- }
Hi Vandeso,
BeantwoordenVerwijderenNice post ,and thanks for sharing .
Sharepoint Developers
Thx!
Verwijderen