How to get the entity schema name list registered in your Dynamics CRM Organization using C#.

Use the following code for fetching entity list names in your console application:

  public static EntityMetadata[] GetEntities(IOrganizationService organizationService)
            Dictionary attributesData = new Dictionary();
            RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
            RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
            metaDataRequest.EntityFilters = EntityFilters.Entity;

            // Execute the request.

            metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);

            var entities = metaDataResponse.EntityMetadata;

            return entities;

        public static void PrintEntitySchemaNames()
            OrganizationServiceProxy _orgservice = CreateCrmServiceObjectOnline();

            #region GivesTHeListOfAllEntitiesInAnOrganization
            var allEntities = GetEntities(_orgservice);
            foreach (EntityMetadata Entity in allEntities)

 public static OrganizationServiceProxy CreateCrmServiceObjectOnPremise()

            OrganizationServiceProxy srvOnline = null;
            string strServerUrl = "YourServerUrl + "/" + OrgName";
            string userId = "UserName";
            string password = "passWord";
            string DomainName = "Domain";

            Uri orgUri;
            orgUri = new Uri(strServerUrl + "/XRMServices/2011/Organization.svc");

            IServiceManagement orgServiceManagement =

            AuthenticationCredentials creds = new AuthenticationCredentials();
            creds.ClientCredentials.UserName.UserName = userId;
            creds.ClientCredentials.UserName.Password = password;
            AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(creds);

            ClientCredentials credentials = new ClientCredentials();

            credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userId, password, DomainName);

                srvOnline = new OrganizationServiceProxy(orgUri, null, credentials, null);
            catch (Exception ex)
                Console.WriteLine("Error Occurs: " + ex.Message);

            return srvOnline;

//If your CRM is Online
        public static OrganizationServiceProxy CreateCrmServiceObjectOnline()
            OrganizationServiceProxy oService = null;
            string UrlPrefix = string.Empty;
            string ServerUrl = string.Empty;
            string DomainName = string.Empty;
            string DomainUserId = string.Empty;
            string DomainPassword = string.Empty;

            UrlPrefix = "https://";
            ServerUrl = "";
            DomainUserId = "";
            DomainPassword = "passWord";

            ClientCredentials credentials = new ClientCredentials();

            credentials.UserName.UserName = DomainUserId;
            credentials.UserName.Password = DomainPassword;
            Uri OrganizationUri = new Uri(UrlPrefix + ServerUrl + "/XRMServices/2011/Organization.svc");
                oService = new OrganizationServiceProxy(OrganizationUri, null, credentials, null);
            catch (Exception ex)

            return oService;


Popular posts from this blog

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

How to import CSV files into DataTable in C#

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

go to top image