Kontakt

Add Contact Image to Experience Profile in Sitecore 9

Technical Leader
Valtech, India

22. Dezember 2018

Adding contact image in Sitecore 9 is pretty straight forward, you might come across the requirement where you have to update the contact profile image in xProfile based on contact social profile or custom image URL.

xProfile-Image-1.pngThe code below can be used to set the profile image using Avatar Facet.


var trackerIdentifier = new
IdentifiedContactRfence("xDB.Tracker",Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString("N"));

using (XConnectClient client =
Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())

{
var contact=
client.Get<Sitecore.XConnect.Contact>
(trackerIdentifierSitecore.XConnect.ContactExpandOptions());

if (contact != null)
{
var profileImageUrl = "profile URL comes here";
var objWebClient = new
System.Net.WebClient();
byte[] profileImageBytes =
objWebClient.DownloadData(profileImageUrl);
string mimeType= "image/jpeg";
client.SetFacet<Avatar>(contact,
Avatar.DefaultFacetKey, new Avatar(mimeType, profileImageBytes)
{
MimeType= mimeType,
Picture= profileImageBytes
});
client.Submit():
}
}

Hope this helps!

Happy learning!

 

Article was originally published on Ankit Joshi's Sitecore blog: Add contact image to experience profile in Sitecore 9

Kontakt

Wir freuen uns auf Ihre Nachricht! Bitte füllen Sie das Formular aus. Der zuständige Mitarbeiter unseres Büros wird sich dann mit Ihnen in Verbindung setzen.
Sollten Sie ein alternatives Format und/oder Unterstützung bei der Kommunikation benötigen, um uns Feedback zu geben, wenden Sie sich bitte an Sheree Atcheson.

Let's reinvent the future