コード例 #1
0
        public void UpdateUserProfilePhoto(O365Profile person, O365Service service, Stream photoStream)
        {
            switch (service)
            {
            case O365Service.Spo:

                var clientContext = GetSpoClientContextForSite(SpoSite.Admin);

                UpdateSpoPhoto(clientContext, person.Upn, photoStream);

                return;

            case O365Service.Exo:

                UpdateExoPhoto(person.Upn, photoStream);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(service), service, null);
            }
        }
コード例 #2
0
        public MemoryStream DownloadProfilePhoto(O365Profile person, O365Service service)
        {
            switch (service)
            {
            case O365Service.Spo:

                var clientContext = GetSpoClientContextForSite(SpoSite.MySite);

                var uri = person.SpoProfilePictureUrlLarge;
                var serverrelativePath = uri.AbsolutePath;

                var memoryStream = new MemoryStream();

                using (FileInformation f = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, serverrelativePath))
                {
                    f.Stream.CopyTo(memoryStream);
                }

                return(memoryStream);

            case O365Service.Exo:

                var exo     = GetExoClientContext();
                var results = exo.GetUserPhoto(person.Upn.Upn, "HR648x648", string.Empty);

                if (results.Status == GetUserPhotoStatus.PhotoReturned)
                {
                    var picStream = new MemoryStream(results.Photo);
                    return(picStream);
                }
                else
                {
                    throw new FileNotFoundException($"Failed to get photo from Exo for {person.Upn.Upn}");
                }

            default:
                throw new ArgumentOutOfRangeException(nameof(service), service, null);
            }
        }