The below method can be used to retrieve the image that is stored in an entity record.
public static byte[] GetEntityImage(string entityName, Guid entityId, IOrganizationService service)
{
try
{
QueryExpression query = new QueryExpression(entityName);
query.ColumnSet = new ColumnSet("entityimage");
query.Criteria = new FilterExpression(LogicalOperator.And);
query.Criteria.AddCondition(entityName + "id", ConditionOperator.Equal, entityId);
EntityCollection collection = service.RetrieveMultiple(query);
if (collection.Entities[0].Contains("entityimage"))
{
return collection.Entities[0]["entityimage"] as byte[];
}
}
catch (Exception ex)
{
//WriteErrorLog(entityName, ex.ToString(), service);
}
return null;
}
No comments:
Post a Comment