public static SetDisplayPictureResult SaveDisplayPicture(UserContext userContext)
        {
            SetDisplayPictureResult setDisplayPictureResult = DisplayPictureUtility.SaveToAD(userContext, false);

            if (setDisplayPictureResult.ResultCode != SetDisplayPictureResultCode.NoError)
            {
                return(setDisplayPictureResult);
            }
            string imageSmallHtml = string.Empty;
            string imageLargeHtml = string.Empty;
            string adpictureUrl   = RenderingUtilities.GetADPictureUrl(userContext.ExchangePrincipal.LegacyDn, "EX", userContext, true);

            using (StringWriter stringWriter = new StringWriter())
            {
                RenderingUtilities.RenderDisplayPictureImage(stringWriter, userContext, adpictureUrl, 64, true, ThemeFileId.DoughboyPerson);
                imageLargeHtml = stringWriter.ToString();
            }
            using (StringWriter stringWriter2 = new StringWriter())
            {
                RenderingUtilities.RenderDisplayPictureImage(stringWriter2, userContext, adpictureUrl, 32, true, ThemeFileId.DoughboyPersonSmall);
                imageSmallHtml = stringWriter2.ToString();
            }
            setDisplayPictureResult.SetSuccessResult(imageSmallHtml, imageLargeHtml);
            return(setDisplayPictureResult);
        }
        public static SetDisplayPictureResult ClearDisplayPicture(UserContext userContext)
        {
            SetDisplayPictureResult setDisplayPictureResult = DisplayPictureUtility.SaveToAD(userContext, true);

            if (setDisplayPictureResult.ResultCode != SetDisplayPictureResultCode.NoError)
            {
                return(setDisplayPictureResult);
            }
            string imageSmallHtml = string.Empty;
            string imageLargeHtml = string.Empty;

            using (StringWriter stringWriter = new StringWriter())
            {
                RenderingUtilities.RenderDisplayPictureImage(stringWriter, userContext, string.Empty, 64, true, ThemeFileId.DoughboyPerson);
                imageLargeHtml = stringWriter.ToString();
            }
            using (StringWriter stringWriter2 = new StringWriter())
            {
                RenderingUtilities.RenderDisplayPictureImage(stringWriter2, userContext, string.Empty, 32, true, ThemeFileId.DoughboyPersonSmall);
                imageSmallHtml = stringWriter2.ToString();
            }
            setDisplayPictureResult.SetSuccessResult(imageSmallHtml, imageLargeHtml);
            return(setDisplayPictureResult);
        }