How to get user picture using Lync APIs

n
n

nI was exploring the Lync APIs after installing LyncnSDK on my machine and as a curiosity tried to display the users communicator /nLync Image in custom control.

n

n

n

nTo get the following example working – you will neednto install the Lync SDK or add the references of Lync APIs to your project.nLync SDK can be downloaded here ,nafter this – add the references from location [%root%]\Program Filesn(x86)\Microsoft Lync\SDK\Assemblies\Desktop\Microsoft.LyncModel.dll to yournproject.

n

n

n

nI created one sample Silverlight project where I took Silverlightnimage control and tried to provide the source. This control takes source asneither full path of image or you can assign the BitMap Imag stream.

n

n

n

nI created one entity class named – UserEntity whichnholds BitMapImage as a property.

n

npublic class UserEntity

n

n{

n

n    public BitmapImagenUserImage { get; set;n}

n

n}

n

n

n

nHere is the xaml for Silverlight control , Binding isnadded as BitMapImage stream

n

n

n

n<Image Name=”userImage” Source=”{Binding Path=UserImage}” Margin=”2,2,2,2″ Height=”40″ Width=”40″></Image>

n

n

n

nNow the function to get user image

n

n

n

npublic partial class MainPage : UserControl

n

n{

n

n  List<UserEntity>nallUsers = new List<UserEntity>();

n

n  LyncClient client;

n

n   npublic MainPage()

n

n  {

n

n   nInitializeComponent();

n

n    client = LyncClient.GetClient();

n

n   

n

n    UserEntity userObjet = new UserEntity();

n

n

n

n    if (client != null)

n

n    {                    

n

n       ContactManager cManager = client.ContactManager;

n

n       ifn(cManager != null)

n

n       {

n

n         Contactncontact = cManager.GetContactByUri(“useremail@domain.com”);

n

n         if (contactn!= null)

n

n         {

n

n           List<ContactInformationType> ciList = new List<ContactInformationType>();

n

n           ciList.Add(ContactInformationType.Photo);

n

n           IDictionary<ContactInformationType, object>ndic = null;

n

n           dic =ncontact.GetContactInformation(ciList);

n

n           if (dic != null)

n

n           {

n

n             StreamnphotoStream = dic[ContactInformationType.Photo]nas Stream;

n

n             ifn(photoStream != null)

n

n             {

n

n               BitmapImagenuserImageBitMap = new BitmapImage();

n

n               userImageBitMap.SetSource(photoStream);

n

n              nuserObjet.UserImage = userImageBitMap;

n

n            n}

n

n           }

n

n         }

n

n      }

n

n    }

n

n         allUsers.Add(userObjet);

n

n  if (allUsers != null && allUsers.Count > 0)

n

n         {

n

n           userImage.ItemsSource = allUsers;

n

n n}

n

n  }

n

n

n

Leave a Comment