locked
user name RRS feed

  • Question

  • retrieve crm current user login name using c# console application

    please help me

    thanks in advance

    Thursday, October 4, 2012 3:51 PM

Answers

  • Hello,

    Recheck following code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel.Description;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Uri organizationUri = new Uri("http://[Your crm server here]:[Port]/[Organization Name]/XRMServices/2011/Organization.svc");
                Uri homeRealmUri = null;
                ClientCredentials credentials = new ClientCredentials();
                credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
                OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
                IOrganizationService _service = (IOrganizationService)orgProxy;
    
                QueryExpression query = new QueryExpression("systemuser")
                    {
                        ColumnSet = new ColumnSet(new string[] { "domainname" })
                    };
                query.Criteria.AddCondition("systemuserid", ConditionOperator.EqualUserId, null);
    
                Entity entity = _service.RetrieveMultiple(query).Entities[0];
    
                Console.WriteLine(entity["domainname"]);
                Console.ReadLine();
            }
        }
    }
    

    This code is 100% created based on article - http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/


    Freelance Developer for Dynamics CRM 4.0/2011

    Thursday, October 4, 2012 4:02 PM
    Moderator