web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Workflow activity to set entity image

(0) ShareShare
ReportReport
Posted on by 695

I'm attempting to set the entityimage in CRM online using  SampleCode\CS\GeneralProgramming\LateBound\EntityImages.cs from the sdk as a baseline. However, the File.ReadAllBytes() is throwing a security error.  I'm assuming that the System.IO cannot be used in isolation mode, so is there a way to programmatically set the entity image in CRM online?

Here's what I have:

var EntID = context.PrimaryEntityId;

var EntName = context.PrimaryEntityName;

ColumnSet cols = new ColumnSet(

new String[] { "entityimage", "asi_businessline" });

 

//Get the Record

Entity tr = service.Retrieve(EntName, EntID, cols);

string busLine = tr.FormattedValues["asi_businessline"].ToString();

switch (busLine)

{

case "Neebo":

case "NMRP":

{

tr["entityimage"] = File.ReadAllBytes("//WebResources/asi_NEBookLogo.png");

break;

}

case "Textbook Underground":

tr["entityimage"] = File.ReadAllBytes("northendteleservices.crm.dynamics.com/.../asi_TULogo.png");

break;

default:

tr["entityimage"] = null;

break;

}

service.Update(tr);

And the error:

Exception: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

*This post is locked for comments

I have the same question (0)
  • Royal King Profile Picture
    27,686 on at

    Workflow/plugins registred in isolation mode does not have rights to access system resources like file, folder of the system. Rather then using workflow if you write console or windows application using CRM organization service API you should be able to use same code what you have to upload images.

  • TonyN Profile Picture
    695 on at

    Are there any methods of converting to a byte array that can be used in isolation mode?

  • Verified answer
    TonyN Profile Picture
    695 on at

    I was able to grab the byte string stored in the database with the service and hard code it.

    https://orgname.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/WebResourceSet?$filter=Name eq 'asi_TULogo.png'&$select=Name,Content

    string tu = "iVBORw0KGgoAAAANSUhEUgAAACcAAAAqCAYAAAAwPULrAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAD8SURBVFhH7daxCoJQFMbxT3FVcBKnoM0lcrKEhnqm6KlqC6KGeoRA6hV0NISaxAq5s3m/IC5xftM9Tf/uHTzWcDB4wkBJksBWZyNJHEviWBLHkjiWNUtT7S9E0zQoikJN3RzHQRAEaupvHMewnm9q7q2qKsSjkZq6RVGE7W6nJj1mP+thv+99c/PFon0m9ubyPMf1cmnPn/i+D62t5Jxl8DyPjtus11gtl+35E9lKviFxLIljSRxL4lgSxzI6jtpK6rrG6XhUv3ZzXReT6bQ9624lVBzrr1YmrZsLwxC2zf+f++OBW1mqqZv2s/6SbMLfkDiWxLEkjmVwHPACw1FSAA1RvyIAAAAASUVORK5CYII=";

    and then convert the string back to byte array

    tr["entityimage"] = Convert.FromBase64String(tu);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans