Skip to main content

Cloud

Lync and My Sites (Update My Site status with Lync Personal Note)

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.
image image
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 Smile ) 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

image
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

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

.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode, .ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .rem
{color:#008000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .str
{color:#006080;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .op
{color:#0000c0;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .preproc
{color:#cc6633;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .html
{color:#800000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .attr
{color:#ff0000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .lnum
{color:#606060;}
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:                     {
 7: 
 8:                         usrStatus = lyncClient.Self.Contact.GetContactInformation(ContactInformationType.PersonalNote)
 9:                                       as string;
 10:                         //Update your My Site using web service.
 11: 
 12:                     }
 13:                     catch (LyncClientException se)
 14:                     {
 15:                             //Handle Exception 
 16:                     }
 17:                     catch (SystemException systemException)
 18:                     {
 19:                             // Handle other exceptions.
 20:                       }
 21: 
 22:                 }
 23:             }
 24: 

.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode, .ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .rem
{color:#008000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .str
{color:#006080;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .op
{color:#0000c0;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .preproc
{color:#cc6633;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .html
{color:#800000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .attr
{color:#ff0000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .lnum
{color:#606060;}
Step 4: To update your My Site status, create a service reference to “https://Your SharePoint Web Application/_vti_bin/UserProfileService.asmx”

 1: UserProfileService.UserProfileServiceSoapClient mySiteClient = new UserProfileService.UserProfileServiceSoapClient();
 2:                         mySiteClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
 3:                         mySiteClient.ClientCredentials.Windows.AllowNtlm = true;
 4:                         var data = mySiteClient.GetUserProfileByName(Environment.UserDomainName + "\" + Environment.UserName);
 5:                         var myStatusProperty = (from d in data
 6:                                               where d.Name == "SPS-StatusNotes"
 7:                                               select d).FirstOrDefault();
 8:                         if (myStatusProperty != null && myStatusProperty.Values != null && myStatusProperty.Values.Length > 0)
 9:                         {
 10: //Check if the My Site status is different from the Lync Client
 11:                             if (string.Compare(myStatusProperty.Values[0].Value.ToString(), usrStatus, true) != 0)
 12:                             {
 13:                                 myStatusProperty.Values[0].Value = usrStatus;
 14:                                 isChanged = true;
 15:                             }
 16: 
 17:                         }
 18:                         else
 19:                         {
 20:                             myStatusProperty.Values = new UserProfileService.ValueData[1];
 21:                             myStatusProperty.Values[0] = new UserProfileService.ValueData();
 22:                             myStatusProperty.Values[0].Value = usrStatus;
 23:                             isChanged = true;
 24:                         }
 25:                         if (isChanged)
 26:                         {
 27: //Update the My Site status only if the status is different from the Lync Client
 28:                             myStatusProperty.IsValueChanged = true;
 29:                             mySiteClient.ModifyUserPropertyByAccountName(Environment.UserDomainName + "\" + Environment.UserName, new UserProfileService.PropertyData[] { myStatusProperty });
 30:                         }

.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode, .ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{font-size:small;color:black;font-family:consolas, “Courier New”, courier, monospace;background-color:#ffffff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode pre
{margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .rem
{color:#008000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .kwrd
{color:#0000ff;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .str
{color:#006080;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .op
{color:#0000c0;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .preproc
{color:#cc6633;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .asp
{background-color:#ffff00;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .html
{color:#800000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .attr
{color:#ff0000;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClass307D0FAC3A8A4C81AB3106CF7836F1CB .csharpcode .lnum
{color:#606060;}
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Amol Ajgaonkar

More from this Author

Follow Us