
Hi,
I want to import a couple of hundred pictures to different records in the Product entity in CRM. I figured there must be a way to do that using my image path and the Product ID in CRM, and then connect it to the field Entity Image on the Product entity. This field is not visible when I am trying to import data. Neither is it visible on the form, how come since I would assume it is by default on the form since I can add the pictures manually.
Any ideas?
Thanks!
/Isabell
*This post is locked for comments
I have the same question (0)You can dev a batch using the CRM SDK to solve this:
First get the entitycollection of Products and do a list of correspondent path string.
Iterate the entitycollection passing the pair <Entity record, path>
/// <summary>
/// Receive the entity record and the path of file
/// </summary>
public void UploadPhoto(Entity _entity, string path)
{
try
{
Image photoContato = Image.FromFile(path);
_entity["entityimage"] = ImageToByteArray(photoContato);
_service.Update(_entity);
}
catch (Exception ex)
{
Console.Writeline(ex.Message + "\n" + path);
}
}
public static byte[] ImageToByteArray(System.Drawing.Image image)
{
using (var ms = new MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
return ms.ToArray();
}
}
If this solves please "Like" and mark as "Verified Answer"