How to retrieve display name of an attribute in Dynamics CRM using C#

Recently, i got a requirement to get the display name of attributed of an entity in C# code. This was basically a part of building an application to retrieve the Name and option set values of all option sets of any selected entity.

Anyway, i’ll update about that later when the application is finished but for now i feel sharing the code to retrieve the Label name of attributes which can give you the label of attribute if you pass it the schema name of entity, schema name of attribute and Iorganisation service object.

Class to include:

Write  “using Microsoft.Xrm.Sdk.Messages;” to include the same.


Code Snippet:


public static string RetrieveAttributeDisplayName( string EntitySchemaName, string AttributeSchemaName, IOrganizationService service)

RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
 EntityLogicalName = EntitySchemaName,
 LogicalName = AttributeSchemaName,
 RetrieveAsIfPublished = true
 RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
 AttributeMetadata retrievedAttributeMetadata = (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata;

//Get Length
 // Int32 length = (Int32)((Microsoft.Xrm.Sdk.Metadata.StringAttributeMetadata)retrievedAttributeMetadata).MaxLength;
 return retrievedAttributeMetadata.DisplayName.UserLocalizedLabel.Label;


Hope the post will be helpful.






2 thoughts on “How to retrieve display name of an attribute in Dynamics CRM using C#

Add yours

  1. HI,

    I have a requirement to know the Entity Schema Name based on the Attribute Schema Name.

    Is this even possible to get this value using sdk code in C#?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: