Get User Picture using Lync (Skye for Business) SDK

  1. public class UserEntity    
  2. {    
  3.    public BitmapImage UserImage { getset; }    
  4. }    
  1. public partial class MainPage : UserControl    
  2. {    
  3.   List<UserEntity> allUsers = new List<UserEntity>();    
  4.   LyncClient client;    
  5.     public MainPage()    
  6.   {    
  7.     InitializeComponent();    
  8.     client = LyncClient.GetClient();    
  9.        
  10.     UserEntity userObjet = new UserEntity();    
  11.     
  12.     if (client != null)    
  13.     {                        
  14.        ContactManager cManager = client.ContactManager;    
  15.        if (cManager != null)    
  16.        {    
  17.          Contact contact = cManager.GetContactByUri("[email protected]");    
  18.          if (contact != null)    
  19.          {    
  20.            List<ContactInformationType> ciList = new List<ContactInformationType>();    
  21.            ciList.Add(ContactInformationType.Photo);    
  22.            IDictionary<ContactInformationType, object> dic = null;    
  23.            dic = contact.GetContactInformation(ciList);    
  24.            if (dic != null)    
  25.            {    
  26.              Stream photoStream = dic[ContactInformationType.Photo] as Stream;    
  27.              if (photoStream != null)    
  28.              {    
  29.                BitmapImage userImageBitMap = new BitmapImage();    
  30.                userImageBitMap.SetSource(photoStream);    
  31.                userObjet.UserImage = userImageBitMap;    
  32.              }    
  33.            }    
  34.          }    
  35.       }    
  36.     }    
  37.     allUsers.Add(userObjet);    
  38.   if (allUsers != null && allUsers.Count > 0)    
  39.          {    
  40.            userImage.ItemsSource = allUsers;    
  41.   }    
  42.   }    
  1. <Image Name="userImage" Source="{Binding Path=UserImage}" Margin="2,2,2,2" Height="40" Width="40"></Image>