D365 CRM: Set the Entity Image on an Entity in Dynamics CRM using C#



  • When you create a new entity record supported with Entity Image, by default will appear like this, with two letters that contain in the primary name field:


     
    If you like to change that image using the SDK API, you need to set the attribute “entityimage” with a valid byte array of an image file. It is recommended by Microsoft to use a 144x144.png for best results. Other viable dimensions are: 60x80, 144x400, 400x500, 400x144.

    Here a sample code:

    -Using Base64 image:

    1.    Entity updateAccountImage = new Entity("account", accountId);
         
    2.    updateAccountImage["entityimage"] = Convert.FromBase64String(base64img); // Base64 of the image file
         
    3.    service.Update(updateAccountImage);

    -Using Byte Array image:

    1.    Entity updateAccountImage = new Entity("account", accountId);
    2.    updateAccountImage["entityimage"] = File.ReadAllBytes(fileName); // Byte[] of the image file in disk
         
    3.    service.Update(updateAccountImage);

     

    Original Source:
    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/sample-set-retrieve-entity-images?view=op-9-1

    Enjoy it!


  • Comments



Add a Comment