コード例 #1
0
        /// <summary>
        /// Retrieves the picture of a contact, if any
        /// </summary>
        /// <param name="contactId">The ID of the contact</param>
        /// <returns>The picture as a binary Stream</returns>
        public static Stream GetContactPhoto(String contactId)
        {
            Stream result      = null;
            String contentType = "image/png";

            try
            {
                result = MicrosoftGraphHelper.MakeGetRequestForStream(
                    String.Format("{0}me/contacts/{1}/photo/$value",
                                  MicrosoftGraphHelper.MicrosoftGraphV1BaseUri, contactId),
                    contentType);
            }
            catch (ApplicationException ex)
            {
                HttpException httpException = ex.InnerException as HttpException;
                if (httpException != null && httpException.GetHttpCode() == 404)
                {
                    // If 404 -> The contact does not have a picture
                    // Keep NULL value for result
                    result = null;
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// This method retrieves the photo of a group from Azure AD
        /// </summary>
        /// <param name="groupId">The ID of the group</param>
        /// <returns>The group's photo retrieved from Azure AD</returns>
        public static Stream GetGroupPhoto(String groupId)
        {
            String contentType = "image/png";

            var result = MicrosoftGraphHelper.MakeGetRequestForStream(
                String.Format("{0}groups/{1}/photo/$value",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri, groupId),
                contentType);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// This method returns the content of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <returns>The content of the file as a Stream</returns>
        public static Stream GetFileContent(String driveId, String fileId, String contentType)
        {
            Stream fileContent = MicrosoftGraphHelper.MakeGetRequestForStream(
                String.Format("{0}drives/{1}/items/{2}/content",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId),
                contentType);

            return(fileContent);
        }
コード例 #4
0
        /// <summary>
        /// This method returns the thumbnails of a specific file by ID
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="fileId">The ID of the target file</param>
        /// <returns>The file thumbnails for the specific file</returns>
        public static Stream GetFileThumbnailImage(String driveId, String fileId, ThumbnailSize size)
        {
            String jsonResponse = MicrosoftGraphHelper.MakeGetRequestForString(
                String.Format("{0}drives/{1}/items/{2}/thumbnails/0/{3}",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              fileId,
                              size.ToString().ToLower()));

            var thumbnail = JsonConvert.DeserializeObject <Thumbnail>(jsonResponse);

            var thumbnailImageStream = MicrosoftGraphHelper.MakeGetRequestForStream(
                thumbnail.Url,
                "image/jpeg");

            return(thumbnailImageStream);
        }