How to Update My Site status with Lync Personal Note in SharePoint

If you have noticed, Lync’s personal note does not sync with your “My Site” status. It would’ve been great if there was a way to set the My Site link in the Lync client and it would automatically set the status.

How to Update My Site status with Lync Personal Note in SharePoint

How to Update My Site status with Lync Personal Note in SharePoint

To accomplish the above we have to use the Lync client SDK which can be downloaded from here.

The Lync Client SDK provides a rich set of API to communicate with the Lync server. The API actually uses the Lync client’s endpoints to communicate with the Lync server. Hence, for the API to work, the Lync client needs to be running on the machine.The SDK also provides all the controls that you can see in the Lync client. E.g: Contact List, Contact search, Contact card, etc. In theory it should let you build the entire client using the SDK. (But you would need Lync client running ) The general idea here is to build a Win Forms application that just minimizes to the notification area and listens to any changes made to the Personal Note in the Lync client. Once we capture that information, it is as simple as calling a web service to update the My Site status.

Here is a rough guideline.

Step 1: Create a Win Forms application and add the following references.

  • Microsoft.Lync.Model
  • Microsoft.Lync.Utilities

How to Update My Site status with Lync Personal Note in SharePoint

Step 2: Hook into the Lync client using the SDK.

In the Load event of the form, get an instance of the Lync client and tap into the ContactInformation changed event

LyncClient lyncClient = LyncClient.GetClient();
lyncClient.Self.Contact.ContactInformationChanged += new EventHandler<ContactInformationChangedEventArgs>(Contact_ContactInformationChanged);

Step 3: In the event handler, get the value of the Personal Note and update your MySite

1:  if (lyncClient != null && lyncClient.State == ClientState.SignedIn)
2: {
3: if (e.ChangedContactInformation.Contains(ContactInformationType.PersonalNote))
4: {
5: try
6: {
8: usrStatus = lyncClient.Self.Contact.GetContactInformation(ContactInformationType.PersonalNote)
9: as string;
10: //Update your My Site using web service.
12: }
13: catch (LyncClientException se)
14: {
15: //Handle Exception
16: }
17: catch (SystemException systemException)
18: {
19: // Handle other exceptions.
20: }
22: }
23: }

UserProfileService.UserProfileServiceSoapClient mySiteClient = new UserProfileService.UserProfileServiceSoapClient();
mySiteClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
mySiteClient.ClientCredentials.Windows.AllowNtlm = true;
var data = mySiteClient.GetUserProfileByName(Environment.UserDomainName + "\\" + Environment.UserName);
var myStatusProperty = (from d in data
where d.Name == "
select d).FirstOrDefault();
if (myStatusProperty != null && myStatusProperty.Values != null && myStatusProperty.Values.Length > 0)
//Check if the My Site status is different from the Lync Client
if (string.Compare(myStatusProperty.Values[0].Value.ToString(), usrStatus, true) != 0)
myStatusProperty.Values[0].Value = usrStatus;
isChanged = true;

myStatusProperty.Values = new UserProfileService.ValueData[1];
myStatusProperty.Values[0] = new UserProfileService.ValueData();
myStatusProperty.Values[0].Value = usrStatus;
isChanged = true;
if (isChanged)
//Update the My Site status only if the status is different from the Lync Client
myStatusProperty.IsValueChanged = true;
mySiteClient.ModifyUserPropertyByAccountName(Environment.UserDomainName + "
\\" + Environment.UserName, new UserProfileService.PropertyData[] { myStatusProperty });

If you are well versed with Win Forms applications, you can minimize the application to the notification so that the application is not visible to the user but the application can still display status and progress information to the user.