January 8, 2017

Add profile image to Sitecore contact

You can use below method to associate image to Contact.

using (new SecurityDisabler())
      {
         
var image = "PASS MEDIA ITEM HERE"
;
         
MediaItem
getmediaItem = masterdb.GetItem(image.ID);
         
var
stream = getmediaItem.GetMediaStream();
         
var memoryStream = new MemoryStream
();
         
if (stream != null
) stream.CopyTo(memoryStream);
         
var pictureFacet = Tracker.Current.Contact.GetFacet<IContactPicture>("Picture"
);
          pictureFacet.Picture = memoryStream.ToArray();
          pictureFacet.MimeType = getmediaItem.MimeType;
      }

No comments:

Post a Comment