Search code examples
c#dynamics-crm-2011access-rights

How to check if user have ReadAccess for an account in Dynamics CRM usind C#


I am following this walkthrough for getting the access of a user to an account in dynamics crm using C#. When I tried to check that if user have AppendAccess it is not working properly and while debugging I found these rights in the following form. enter image description here

I want to check if a user have AppendAccess then do the next. what I tried is in the following:

if(principalAccessRes.AccessRights.Equal("AppendAccess "))
{
Console.WriteLine("User have Append Access");
}

Solution

  • Because AccessRights is a [Flag] you need to check if the access rights response includes (HAVE) instead of equal.

    if(principalAccessRes.AccessRights.HasFlag(AccessRights.AppendAccess))
    {
       Console.WriteLine("User have Append Access");
    }